Hello Guest it is May 09, 2021, 04:05:42 PM

Author Topic: Mach4 Serial Port Support  (Read 7133 times)

0 Members and 1 Guest are viewing this topic.

Mach4 Serial Port Support
« 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.

Offline TPS

*
  •  2,124 2,124
    • View Profile
Re: Mach4 Serial Port Support
« Reply #1 on: March 06, 2015, 07:45:52 AM »
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
anything is possible, just try to do it.
if you find some mistakes, in my bad bavarian english,they are yours.

Offline ger21

*
  • *
  •  6,292 6,292
    • View Profile
    • The CNC Woodworker
Re: Mach4 Serial Port Support
« Reply #2 on: March 06, 2015, 07:47:23 AM »
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.
Gerry

2010 Screenset
http://www.thecncwoodworker.com/2010.html

JointCAM Dovetail and Box Joint software
http://www.g-forcecnc.com/jointcam.html
Re: Mach4 Serial Port Support
« Reply #3 on: March 06, 2015, 10:31:49 AM »
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.

Offline ger21

*
  • *
  •  6,292 6,292
    • View Profile
    • The CNC Woodworker
Re: Mach4 Serial Port Support
« Reply #4 on: March 06, 2015, 11:23:42 AM »
Then forget about my previous reply.
I don't know the answer to your question.
Gerry

2010 Screenset
http://www.thecncwoodworker.com/2010.html

JointCAM Dovetail and Box Joint software
http://www.g-forcecnc.com/jointcam.html
Re: Mach4 Serial Port Support
« Reply #5 on: March 06, 2015, 03:18:02 PM »
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

I don't know if it will work in Mach4 but I will put it on my list of stuff to try.
Re: Mach4 Serial Port Support
« Reply #6 on: July 22, 2015, 08:41:23 PM »
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" ?
Re: Mach4 Serial Port Support
« Reply #7 on: July 22, 2015, 08:47:18 PM »
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
Re: Mach4 Serial Port Support
« Reply #8 on: November 18, 2015, 06:51:33 PM »
Tgirard;

Does this mean you got RS232 serial to work w/ MACH 4 - or were you only able to get it to load?
Thanks.
Re: Mach4 Serial Port Support
« Reply #9 on: November 18, 2015, 07:11:28 PM »
Hey MadDog,
I was not able to make a connection by dropping in the luars232.dll. Have you had any luck?