nigelr99
asked on
Accessing Serial Port in Access / VBA
Hi,
I have a need to send simple text/hex values to a serial port from an Access application (which controls some relays incidentally). I've read many long articles regarding MSCOMM and variants thereof but I'm sure it shouldn't be that difficult.
From a previous answer to another question, I have arrived at the code below which is nearly there except Windows seems to be adding data at the start and end of my own.
I'm using a serial port 'sniffer' and when I run the procedure shown, I see the data I'm sending but also 22h at the start and then 22h,2Ch at the end - is there a way to remove this extra data? I guess it's to do with the port communication settings but I'm not sure how to configure those within VBA.
Any help would be appreciated.
I have a need to send simple text/hex values to a serial port from an Access application (which controls some relays incidentally). I've read many long articles regarding MSCOMM and variants thereof but I'm sure it shouldn't be that difficult.
From a previous answer to another question, I have arrived at the code below which is nearly there except Windows seems to be adding data at the start and end of my own.
Global Const stx = 4
Global Const etx = 15
Public Sub relay_on(n)
cmd = 20
mask = 2 ^ (n - 1)
'param1 and 2 both zero
chk = 231
Open "COM3" For Output As #1
Write #1, Chr$(stx) & Chr$(cmd) & Chr$(mask) & Chr$(0) & Chr$(0) & Chr$(chk) & Chr$(etx);
Close #1
End Sub
I'm using a serial port 'sniffer' and when I run the procedure shown, I see the data I'm sending but also 22h at the start and then 22h,2Ch at the end - is there a way to remove this extra data? I guess it's to do with the port communication settings but I'm not sure how to configure those within VBA.
Any help would be appreciated.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Many thanks!