Hello Guest it is March 28, 2024, 06:34:56 PM

Author Topic: using sendserial command in mach3  (Read 3789 times)

0 Members and 1 Guest are viewing this topic.

using sendserial command in mach3
« on: July 12, 2018, 01:08:30 AM »
I have been trying to find a way to run send a text string to an automation direct 4850 stepper drive to use the SCL feature built in.
I can talk to the drive using terminal and can send it commands.
I just cna seem to get the VB script in mach3 to run it. I have setup the serial port in general config and using the call sendserial.

This is just a bit of what I have tried:
Code: [Select]
Sub SendSerial (chars As String)
Call SendSerial ("CJ<cr>")

The CJ stands for commence jogging and the <cr> is a carriage return.
Here is a link to the SCL manual:
https://cdn.automationdirect.com/static/manuals/surestepmanual/scl_manual.pdf

I am wondering id I should use a private declare function to call a serial dll or not or if anyone knows of one. I have spent hours online looking thi sup and can't seem to find anything. I am not awesome at VB but can make my way through it to an extent.

Any help would be greatly appreciated.
Re: using sendserial command in mach3
« Reply #1 on: July 14, 2018, 03:54:28 AM »
So I wanted to update everyone on this in case it could help someone else. This is so I can control 2 stepper motor driven pumps in RPM.

So I got this working. I am using 2 FTDI USB to serial adapters, 2 Automation Direct STP-DRV-4850 stepper drives programed to SCL using 2 Automation Direct STP-MTR-23055 stepper motors.
The USB to serial adapters have been setup to COM2 and COM3.
I have used a DLL file created by an old coworker we no longer use for our equipment. See attachment link below.
I also attached an image of what the buttons and DRO's look like.

Here is the code I came up with for all the buttons and DRO use to send text strings to the drives.

Code: [Select]
'Pump 1 on / change speed VB:

While IsLoading ()
End
Wend

Private Declare Function sendSerialACE Lib "Serial_DLL2.dll" (ByVal cmd As String, ByVal port As String) As String

pmp1spddro=GetUserDRO(2055)

If pmp1spddro < 400 Then
Call sendSerialACE("SJ" & Chr(13),"COM2")
Call SetUserLED (2055,1)
Response=MsgBox("Speed too Low...Range 400-1300",0,"Pump" )
End
End If

If pmp1spddro > 1300 Then
Call sendSerialACE("SJ" & Chr(13),"COM2")
Call SetUserLED (2055,1)
Response=MsgBox("Speed too High...Range 400-1300",0,"Pump" )
End
End If

pmpspd1 = Round ((GetUserDRO(2055)*0.625)/60,4)

If GetUserLED(2055)= 1 Then
Call sendSerialACE("JA10" & Chr(13),"COM2")
Call sendSerialACE("JL200" & Chr(13),"COM2")
Call sendSerialACE("JS1" & Chr(13),"COM2")
Call sendSerialACE("CJ" & Chr(13),"COM2")
Call sendSerialACE("CS" & pmpspd1 & Chr(13),"COM2")
Call SetUserLED (2055,0)

Else
Call sendSerialACE("CS" & pmpspd1 & Chr(13),"COM2")
End If


'Pump 1 Off:

While IsLoading ()
End
Wend

Private Declare Function sendSerialACE Lib "Serial_DLL2.dll" (ByVal cmd As String, ByVal port As String) As String

Call sendSerialACE("SJ" & Chr(13),"COM2")
Call SetUserLED (2055,1)


'Pump 1 Increment Increase:

While IsLoading ()
End
Wend

Private Declare Function sendSerialACE Lib "Serial_DLL2.dll" (ByVal cmd As String, ByVal port As String) As String

pmpinc1 = (GetUserDRO(2055) +  GetUserDRO(2053))  'On Screen DRO

If pmpinc1 > 1300 Then

End
End If

Call SetUserDRO(2055,GetUserDRO(2055) + GetUserDRO(2053))

pmpspd1 = Round ((GetUserDRO(2055)*0.625)/60,4)

Call sendSerialACE("CS" & pmpspd1 & Chr(13),"COM2")


'Pump 1 Increment Decrease:

While IsLoading ()
End
Wend

Private Declare Function sendSerialACE Lib "Serial_DLL2.dll" (ByVal cmd As String, ByVal port As String) As String

pmpinc1 = (GetUserDRO(2055) -  GetUserDRO(2053))  'On Screen DRO

If pmpinc1 < 400 Then

End
End If

Call SetUserDRO(2055,GetUserDRO(2055) - GetUserDRO(2053))

pmpspd1 = Round ((GetUserDRO(2055)*0.625)/60,4)

Call sendSerialACE("CS" & pmpspd1 & Chr(13),"COM2")


'Pump 2 on / change speed VB:

While IsLoading ()
End
Wend

Private Declare Function sendSerialACE Lib "Serial_DLL2.dll" (ByVal cmd As String, ByVal port As String) As String

pmp2spddro=GetUserDRO(2054)

If pmp2spddro < 400 Then
Call sendSerialACE("SJ" & Chr(13),"COM2")
Call SetUserLED (2054,1)
Response=MsgBox("Speed too Low...Range 300-1300",0,"Pump" )
End
End If

If pmp2spddro > 1300 Then
Call sendSerialACE("SJ" & Chr(13),"COM2")
Call SetUserLED (2054,1)
Response=MsgBox("Speed too High...Range 400-1300",0,"Pump" )
End
End If

pmpspd2 = Round ((GetUserDRO(2054)*0.625)/60,4)

If GetUserLED(2054)= 1 Then
Call sendSerialACE("JA10" & Chr(13),"COM3")
Call sendSerialACE("JL200" & Chr(13),"COM3")
Call sendSerialACE("JS1" & Chr(13),"COM3")
Call sendSerialACE("CJ" & Chr(13),"COM3")
Call sendSerialACE("CS" & pmpspd2 & Chr(13),"COM3")
Call SetUserLED (2054,0)

Else
Call sendSerialACE("CS" & pmpspd2 & Chr(13),"COM3")
End If


'Pump 2 Off:

While IsLoading ()
End
Wend

Private Declare Function sendSerialACE Lib "Serial_DLL2.dll" (ByVal cmd As String, ByVal port As String) As String

Call sendSerialACE("SJ" & Chr(13),"COM3")
Call SetUserLED (2054,1)


'Pump 2 Increment Increase:

While IsLoading ()
End
Wend

Private Declare Function sendSerialACE Lib "Serial_DLL2.dll" (ByVal cmd As String, ByVal port As String) As String

pmpinc2 = (GetUserDRO(2054) +  GetUserDRO(2052))  'On Screen DRO

If pmpinc2 > 1300 Then

End
End If

Call SetUserDRO(2054,GetUserDRO(2054) + GetUserDRO(2052))

pmpspd2 = Round ((GetUserDRO(2054)*0.625)/60,4)

Call sendSerialACE("CS" & pmpspd2 & Chr(13),"COM3")


'Pump 2 Increment Decrease:

While IsLoading ()
End
Wend

Private Declare Function sendSerialACE Lib "Serial_DLL2.dll" (ByVal cmd As String, ByVal port As String) As String

pmpinc2 = (GetUserDRO(2054) -  GetUserDRO(2052))  'On Screen DRO

If pmpinc2 < 400 Then

End
End If

Call SetUserDRO(2054,GetUserDRO(2054) - GetUserDRO(2052))

pmpspd2 = Round ((GetUserDRO(2054)*0.625)/60,4)

Call sendSerialACE("CS" & pmpspd2 & Chr(13),"COM3")

I hope the above helps someone as I did a lot of research and trial and error to get this done. If any of you VB guru's see any dirty code please let me know.
Re: using sendserial command in mach3
« Reply #2 on: July 14, 2018, 04:00:13 AM »
As a note in the code you will see I round up to the nearest 4th decimal place as that i the resolution of the CS Change Speed command. Also i have a multiplication for a gear ratio 8:5 (*0.625) and to convert RPM to revolutions per second /60.

Code: [Select]
pmpspd1 = Round ((GetUserDRO(2055)*0.625)/60,4)
I have also set a min and max speed that can be entered 400 to 1300 RPM.

Code: [Select]
pmp1spddro=GetUserDRO(2055)

If pmp1spddro < 400 Then
Call sendSerialACE("SJ" & Chr(13),"COM2")
Call SetUserLED (2055,1)
Response=MsgBox("Speed too Low...Range 400-1300",0,"Pump" )
End
End If

If pmp1spddro > 1300 Then
Call sendSerialACE("SJ" & Chr(13),"COM2")
Call SetUserLED (2055,1)
Response=MsgBox("Speed too High...Range 400-1300",0,"Pump" )
End
End If

Just some extra notes to add to my post.

Offline Tweakie.CNC

*
  • *
  •  9,196 9,196
  • Super Kitty
    • View Profile
Re: using sendserial command in mach3
« Reply #3 on: July 14, 2018, 06:07:54 AM »
Excellent work Tiemann66, thank you for sharing the information.

Tweakie.
PEACE