Author Topic: CnC Mach3 serial cards, I/O  (Read 2423 times)

Offline Dawai

  • Full Member
  • ***
  • Posts: 125
  • Country: us
CnC Mach3 serial cards, I/O
« on: December 27, 2013, 12:32:08 PM »
I ended up writing a vbscript file, you load it into Mach3 gcode by calling it's M-code name, this one M995, initiates the opto22 422 link, sets up modules, and writes (0) position bit on.

I can use it like this, but.. the commands are so close to Modbus transactions of data that mach3 uses there has to be a way>?> 
command string = ">" start of transmission, "FF" Hex address 255, A-Z command register, between 4 bytes and sixteen 4 byte transactions of data per unit.

Anyways.. here is a script that opens up the serial and is working right now.. I have 32 commands related to a 16 I/O board thou.. gets confusing.. and typos kill a gcode program faster than a bullet.

I commented the "other modules commands and do one command per Mcode"
M995-M980 

'******************* vbscript code
'*************** Mach 3 serial opto22 write *********
'*** Authored Cofer 12-26-2013 NORF Gawgia
' Utilizing 16 bit opto22 Pb16hc card & B1 422 serial card. usb-422 adapter on com port 3
Private Declare Function timeGetTime Lib "WINMM.dll" () As Long
Dim M_flag As Boolean
Dim TimeToEnd As Boolean
Dim m_value As Double
Dim i, t As Integer
Dim not_complete As Boolean
Dim Add$, Cmd$, Pl$, Modi$, RetData$, Opto22Err$
Dim modules As Integer
Dim Byte_pick$
Dim pausetime As Long
Dim control_word$(25) 'array for all control g,M,n codes
Dim control_flag(25) As Boolean


Sub MyFunction()
 Dim pwrup As Integer
    Set MSComm1=CreateObject("MSCOMMLib.MSComm")
    Dim t
    MSComm1.Settings = "19200,n,8,1"
    MSComm1.CommPort = 3
    MSComm1.InBufferCount = 0
    MSComm1.PortOpen = True
      If Err Then
         MsgBox "COM" & MSComm1.CommPort & ": not opened, Sorry!"
         Exit Sub
      End If
   '**************************************************************** 
   
     
     
    MSComm1.output=">FFACD" & Chr(13)  'opto22 power up clear at address FF
    Call delay_MS_time(10)
    'MsgBox " reply was " & MScomm1.input
   
    MSComm1.output=">FFI000FAB" & Chr(13)  'configure the first four as outputs 
    Call delay_MS_time(10)
    'MsgBox " reply was " & MScomm1.input
   
    MSComm1.output=">FFK000198" & Chr(13)  'TURN on bit one, opto22 address FF 
    Call delay_MS_time(10)
    'MsgBox " reply was " & MScomm1.input
   
  '   MSComm1.output=">FFK000299" & Chr(13)  'TURN on bit two, opto22 address FF 
  '  Call delay_MS_time(10)
  '  'MsgBox " reply was " & MScomm1.input
   
  '  MSComm1.output=">FFK00049B" & Chr(13)  'TURN on bit three, opto22 address FF 
  '  Call delay_MS_time(10)
  '  'MsgBox " reply was " & MScomm1.input
  ' 
  '  MSComm1.output=">FFK00089F" & Chr(13)  'TURN on bit four, opto22 address FF 
  '  Call delay_MS_time(10)
  '  'MsgBox " reply was " & MScomm1.input
  ' 
  '  MSComm1.output=">FFL000199" & Chr(13)  'TURN OFF bit one, opto22 address FF 
  '  Call delay_MS_time(10)
  '  'MsgBox " reply was " & MScomm1.input
  ' 
  '  MSComm1.output=">FFL00029A" & Chr(13)  'TURN off bit two, opto22 address FF 
  '  Call delay_MS_time(10)
  '  'MsgBox " reply was " & MScomm1.input

   ' MSComm1.output=">FFL00049C" & Chr(13)  'TURN off bit three, opto22 address FF 
   ' Call delay_MS_time(10)
   ' 'MsgBox " reply was " & MScomm1.input
'
 '   MSComm1.output=">FFL0008A0" & Chr(13)  'TURN off bit four, opto22 address FF 
  '  Call delay_MS_time(10)
   ' 'MsgBox " reply was " & MScomm1.input




   
   

   
   
         
    MSComm1.PortOpen = False
    Set MSComm1 = Nothing
End Sub

Private Sub delay_MS_time(MsDelay)
     Dim time_out As Double
     time_out = MsDelay + timeGetTime()
  Do Until time_out <= timeGetTime()
      ' the delay for the steppers accel/decell
     Loop
End Sub

   

I Hung a 24 foot Ibeam this morning in the ceiling by myself, programmed a Arduino this afternoon for a solar project, Helped a buddy out with a electrical motor connection issue on the phone, then cut up a chicken for Hotwings. I'd say it has been a "blessed day" for myself and all those around me.