Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: peterc on March 06, 2015, 02:39:33 AM
-
Is there any support in Mach4 to communicate through serial ports with non-Modbus devices?
I have Allen Bradley and Mitsubishi servo drives that use their own serial protocol. I did not find any LUA commands for serial port functions.
Would like to use two serial ports and hopefully Mach4 has fixed the Mach3 limitation of 1 serial port.
-
Hi,
Would like to use two serial ports and hopefully Mach4 has fixed the Mach3 limitation of 1 serial port.
In Mach3 and VB script you can use more than one serial port:
Sub Main()
Const MyPort = 1 ' COM1
Const MyBaud = "57600" ' bps rate
Const MyThreshold = 6 ' how many characters to receive until done
Const comEvSend = 1 ' enumeration of comm events
Const comEvReceive = 2
Const comEvCTS = 3
Const comEvDSR = 4
Const comEvCD = 5
Const comEvRing = 6
Const comEvEOF = 7
Const comInputModeText = 0 ' enumeration of input mode constants
Const comInputModeBinary = 1
Set objTest = CreateObject ("MSCOMMLib.MSComm", "[/b]MSCommEvent_") ' second parameter (MSCommEvent_) +
' name of event (OnComm) creates the
' event handler that is called when
' the event fires
objTest.CommPort = MyPort ' select a port to use
objTest.InputLen = 0 ' if = 0, will retrieve all waiting chars
objTest.InputMode = comInputModeText ' causes Input() to return string (not array)
objTest.RThreshold = 2 ' must be non-zero to enable receive
objTest.PortOpen = TRUE ' open COM port for use
s = MyBaud & ",n,8,1" ' settings: baud,parity,bits,stop in BSTR
objTest.Settings = s ' send to COM port
msg = "Test Message "
objTest.Output = msg ' send test message out of port
objTest.PortOpen = FALSE ' close port
Set objTest = Nothing ' uninitialize reference pointer
REM ---------------------------------------------------------------------------
End Sub
Sub MSCommEvent_OnComm ' OnComm event handler
Select Case objTest.CommEvent
Case comEvReceive
rxCnt = rxCnt + objTest.InBufferCount
rxBuf = rxBuf & objTest.Input
If rxCnt >= MyThreshold Then
For i = 2 To MyThreshold Step 2
Next
flag = TRUE
rxCnt = 0
End If
Case Else
End Select
End Sub
not testet, but i think it should work.
Thomas
-
Mach4 uses motion controllers to send signals to drives, so you'd need a motion controller that could send commands through the serial port. I don't think one exists.
-
Mach4 uses motion controllers to send signals to drives, so you'd need a motion controller that could send commands through the serial port. I don't think one exists.
I have the drives hooked up and running through a DSPMC board.
What I want to do is retrieve status information from the drives such as Current Load (using one drive as a spindle), fault codes, etc.
-
Then forget about my previous reply.
I don't know the answer to your question.
-
There is a module in LUA to communicate with a serial port (somehow I missed it during my search). luars232.c is the module for serial port communication.
https://github.com/ynezz/librs232/blob/master/bindings/lua/luars232.c (https://github.com/ynezz/librs232/blob/master/bindings/lua/luars232.c)
I don't know if it will work in Mach4 but I will put it on my list of stuff to try.
-
I tried to run a simple test and could not get the luars232.dll to load. I placed the dll in the Mach4Hobby folder. I then wrote
rs232 = require("luars232") to see if it would just load. This was the result:
Compilation successful!
Output: "C:\Mach4Hobby\LuaExamples\Tims.mcc"
Waiting for client connection...
Client connected ok.
At Breakpoint line: 1 file: C:\Mach4Hobby\LuaExamples\Tims.lua
mcLua ERROR: Lua: Error while running chunk
error loading module 'luars232' from file 'C:\Mach4Hobby\luars232.dll':
The specified module could not be found.
stack traceback:
[C]: in ?
[C]: in function 'require'
[string "C:\Mach4Hobby\LuaExamples\Tims.lua"]:1: in main chunk
mcLua ERROR: Lua: Error while running chunk
Debug session finished.
It "Seems" to want to load but gets hung up somewhere. It could definitely be pilot error on my part...
Does the Mach version of Lua use or require "require" ?
-
By the way, I installed the "Lua for Windows" Package which comes with the luars232.dll. When I ran the example for Luars232, everything ran fine. I simply copied the dll file from Lua for Windows to the Mach4Hobby folder
-
Tgirard;
Does this mean you got RS232 serial to work w/ MACH 4 - or were you only able to get it to load?
Thanks.
-
Hey MadDog,
I was not able to make a connection by dropping in the luars232.dll. Have you had any luck?
-
Not yet. Thanks for the quick reply.