hi
i need to make an excel macro that handles serial communication and takes data from two lab balances. I've looked around and found that i can use xmcommcrc or winwedge (others too but these i'm experimenting with).
The result should be that data would be recorded live into an excel sheet where it can be further processed.
I would prefer xmcomm, because then there is no other program running (if anyone can give some reasons why i shouldn't use this...). I have managed to go as far as establishing a connection and reading one value, but i need it to keep recording each time i press the print button on the balance, for example, until i close the port. (for now solving this would be the best solution in my opinion)
With winwedge i've configured the connection and it can take values whenever i send data from the balance, but i haven't had any luck with making the macros for excel to work. I think it's possible to start winwedge when the worksheet is opened, then somehow configure to send the data directly to a sheet. Any help with this is welcome.
in any case, the communication is only one way, balance to pc, so the tutorial given on the xmcomm site won't do...
here is the code for xmcommcrc. It's put together from tutorials about xmcomm and mscomm, and a bit that should handle writing to a column, one row at a time.
Public Sub RequestBalanceData()
' Buffer to hold input string
Dim ln As Integer
'---------------------------------------------------------------------------------------------------
XMCommCRC1.CommPort = Worksheets("Settings").Range("COM_Port")
XMCommCRC1.Settings = Worksheets("Settings").Range("Baud_Rate") & "," & _
Worksheets("Settings").Range("Parity") & "," & _
Worksheets("Settings").Range("Data_Bits") & "," & _
Worksheets("Settings").Range("Stop_Bits")
' Tell the control to read entire buffer when Input
XMCommCRC1.InputMode = 0
XMCommCRC1.PortOpen = True
'---------------------------------------------------------------------------------------------------
Do
Buffer$ = Buffer$ & XMCommCRC1.InputData
DateBuffer$ = "Date:" & XMCommCRC1.InputData
DEL5
Loop Until Len(Buffer$) > 5
ln = Len(Buffer$)
data = Buffer$
Datex = DateBuffer$
sTerminator = vbCrLf
'---------------------------------------------------------------------------------------------------
Dim Lp As Integer
Dim P As Integer
P = 10
Lp = P + 1
Worksheets("Results").Range(Cells(P, 2), Cells(Lp, 2)).Select
Worksheets("Results").Range(Cells(P, 2), Cells(Lp, 2)).Name = "W_range"
Row = 1
Worksheets("Results").Range("W_range").Cells(Row, 1) = data
Row = Row + 1
P = Lp
'---------------------------------------------------------------------------------------------------
Buffer$ = ""
XMCommCRC1.PortOpen = False
End Sub
Private Sub DEL5()
PauseTime = 2 ' Set duration.
Start = Timer ' Set start time.
Do While Timer < Start + PauseTime
DoEvents ' Yield to other processes.
Loop
End Sub
thank you for your time;)