Machsupport Forum
Mach Discussion => General Mach Discussion => Topic started by: denverwelder on July 23, 2009, 11:37:02 AM
-
Is there any way to write a script to send and receive to the serial port?
-
Serial ModBUS is supported, otherwise I think you will need to write a plugin to handle it, think you can send at the moment without but not sure.
Hood
-
Step 1: Find the file mscomm32.ocx and put it in your windows\system32 directory
Step 2: Register it with the operating system using "regsvr32.exe mscomm32.ocx" at the command line
Step 3: Use the following code to open COM1 and send a 'b' character to the port
Set MSComm1 = CreateObject("MSCOMMLib.MSComm")
MSComm1.commport = 1
MSComm1.settings = "57600,N,8,1"
MSComm1.InputLen = 1024
MSComm1.RThreshold = 0
MSComm1.PortOpen = True
MSComm1.Output = "b"
Unfortunately, if this code is run via a button, the port opens and automatic garbage collection appears to close the port after the script is complete. This requires repetitive opening of the port, which can upset devices which watch control codes on the line. I'm currently looking for a workaround for this problem.