Hello Guest it is December 21, 2024, 12:18:10 PM

Author Topic: Serial Port control under cypress enable  (Read 17994 times)

0 Members and 1 Guest are viewing this topic.

Serial Port control under cypress enable
« on: August 22, 2007, 12:28:04 PM »
Hi
I have been trying for some time now to get the serial control to work reliably sending a file "900 bytes text" to my Boxford Duet. When I use the VB script editor and run it, it works perfectly however when I run a G code file and include it as a macro "M20" it stalls after 20-30 bytes, I have HyperTerminal observing the output. Also Mach seems to want to run the macro immediately the G code is loaded, what am I doing wrong I include the small macro I have written. 

Sub intialise_boxford()

message "Initialising Boxford"

For count = 1 To 255 ' Clear buffer seems to help
x = getfifoentry()
Next count

Open "c:\mach3\duet.dat" For Input As #1 ' Open file.

Do While Not EOF(1) ' Loop until end of file.

char = Input (1,#1) ' Read value into variable.

Call sendfifo(char)

Loop

message "Boxford Initialised"

Close #1 ' Close file.

End Sub

Any help would be gratefully appreciated, as this is frustrating as I’m very close to getting everything running.

Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
Re: Serial Port control under cypress enable
« Reply #1 on: August 22, 2007, 05:45:14 PM »
Since your running that as a macro, mach will run it all out, and then keep on going on the Gcode.

What you might have to do is put a "control bit" in your Macro.

At the end of your Macro put:

SystemWaitFor(INPUT#) 'pick a input number
In your serial file, also toward the end before the line above, have it send some command that the machine has to activate some output
that come in on: INPUT#, Mach will pause and wait in your maco, until you machine recieves the full file, since at the end of that file, it will
trigger your physical machine to send to Mach a "I got it", bit. Once the system wait gets that bit (INPUT#) going active, it will drop out of the macro and continue executing your Gcode.

Scott
fun times
Re: Serial Port control under cypress enable
« Reply #2 on: August 23, 2007, 07:50:24 AM »
Hi Thanks for that poppabear I see your point but that isn't the problem, the macro as it was just would not work when running in a script.

I managed to get the file to write to serial by using the following



Sub intialise_boxford()

For i = 1 To 100
getfifoentry()
Next i                                                         ' clear input buffer if there is one?


message "Initialising Boxford"                          ' Start message

Open "c:\mach3\duet.dat" For Input As #1      ' Open file.

Do While Not EOF(1)                                     ' Loop until end of file.

outint = Asc(Input (1,#1))                             ' Read byte into variable.

PutPortByte(1016,outint)                               ' write byte to COM1 Low level but works

GetFIFOentry()                                              ' either adds delay or clears buffer ?
 
Loop                                           ' Get another byte

message "Boxford Initialised"           ' completiion message

playwave "c:\tada.wav"                  ' file has been sent works :-) 

Close #1 ' Close file.                       ' Close file "Duet.dat"

For i = 1 To 1000000                     ' delay give message time to be seen
Next i

message ""                                    ' clear messages off screen

End Sub

Although this works, I think I need to check the transmit status bit on the serial port instead of the (GetFIFOentry()) which I think is just adds a delay, this is a major success and I will be moving on the receiving data soon. however Mach still seems to want to show all messages within the macro when the G code file is loaded, this is stange it doesn't appear to actually run any code it just displays the messages ?
any ideas greatfully received also are the macros running in their own thread ie multitasking?


Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
Re: Serial Port control under cypress enable
« Reply #3 on: August 23, 2007, 08:15:51 AM »
Since you running this script in a Macro, and you want some pauses use this instead (where ever you need pauses)

Code "G4 P1"   'P=seconds (You can use partial seconds)
While IsMoving()
Wend

For your Messages tie them into some kind of:
 If (event) Then
Message("")
End If

***NOTE: as far as I am currently aware of Mach can only SEND serial stuff NOT receive it....You might want to ask Brian about getting the serial to recieve...........Thats why, I had your transmissions from the machine comming in on other inputs.

Scott
fun times

Offline Whacko

*
  •  239 239
  • Happy Days
Re: Serial Port control under cypress enable
« Reply #4 on: August 23, 2007, 01:24:53 PM »
Have you got the modbus option enabled? Also, out of the Mach3 environment, serial I think is only supported with modbus protocol, and includes CRC. That could be why you only get X amount of bytes out. Just a thought, I may be way out.

Whacko
Nothing's impossible
Re: Serial Port control under cypress enable
« Reply #5 on: August 23, 2007, 02:32:12 PM »
Hi
Thanks for the input, I now have mach sending the file using the last bit of script. What may be of of interest to you all is that Mach will receive serial through the VB script, if you plug into another PC using a NULL modem cable and run hyperterminal then run this on your Mach machines VB script.

For i = 1 to 1000
x = getportbyte(1016)     ' Assumes you are using COM1 at &h3F8
putpportbyte(1016)
next i

You will see that every key you press on the terminal PC will be returned to the terminal PC via the VB script of Mach, not very usefull at the momment but just shows bi directional communication is possible, if I can now find the data flow control bits I think it will be possible that Mach can talk to any serially controlled hardware I hope :-)   

Offline Whacko

*
  •  239 239
  • Happy Days
Re: Serial Port control under cypress enable
« Reply #6 on: August 23, 2007, 06:54:10 PM »
The file you want to send, is it constantly appended in the Mach3 environment? Remember, running a script is part of the OS and you could even do the same by running it on it's own without starting Mach3 in a .vbs file. What you are doing now is been taken care of by the OS via the VB Script engine and is meaningless to Mach3.

Whacko
Nothing's impossible
Re: Serial Port control under cypress enable
« Reply #7 on: August 24, 2007, 12:48:35 PM »
Hi
the file is a simple text file containing the microcode for the Boxford Duet the program simple reads it out byte by byte.

The Boxford duet requires that a file is sent to the machine to initialise it, it is more than usefull to do this within the Mach environment as I wish to fuilly integrate the Duet and it works!, on the subject of serial reads the macro may or may not be able to be understood  by Mach but I believe the macro can understand Mach variables and that is all I need as the duet also sends details of gaurd positon, I need to receive one or two bytes just to confirm that the gaurd is in place I am sure I can poke a few bits to acheive this. I have only just within thae last few days started programing with the Macros so I need ideas of what can be acheived. Is the macro multitasking in its own thread?


Cheers

Offline Whacko

*
  •  239 239
  • Happy Days
Re: Serial Port control under cypress enable
« Reply #8 on: August 24, 2007, 01:16:21 PM »
I just want to clear something, is this file only sent at initialisation and not again, or should it be sent whenever the gaurd has been opened/closed/moved?.
The macro will be executed by Mach3 depending on how you implement it. MultiTasking is part of the Windows OS, maybe I don't understand what you mean. I think you want to know if once the macro is started, it will run independantly not under the control of Mach3. You can send the file via your serial port with the VBScript, but you will have to choose a second port if you are using the modbus with Mach3.
I unfortunately do not have experience with the Boxford, but I have lots of experience with serial ports etc.
You can even invoke another process from the VBScript that will run as a thread on its own.
I will try to help you if you give me some more info. The VBScript in Mach3 is actually the proper Windows OS Script engine, and the Cypress information is limited, you can use the MSDN help file for VBScript. There is a lot of possibilities.

Whacko
Nothing's impossible
Re: Serial Port control under cypress enable
« Reply #9 on: August 25, 2007, 06:23:23 AM »
Hi
Thanks for that I will not be using Modbus so I have a dedicated serial port to the Boxford, I will be looking for anything that helps

The general idea is :-

1) start Mach
2) load G code file

The G code File then includes

3) Initialise Boxford Macro ( this is the one we are talking about)
4) Send speed control to Boxford (next TODO list )
5) Get gaurd information/ speed ( continually)
5) run G code
 
The initialise_boxford part of the macro is run only once at the beginning of work( does not need to be sent again unless the machine is switched off/on), if the boxford is already initialised then it will be programmed not to do it again, I do intend however to have this macro home the axis and basically set the machine up, the Guard  postion is also found ( closed / open) and dependant on this I can run the rest of the G code or not, it would be nice however for a gaurd open to control a stop, this means having a serial reception running all the time, I have run out of inputs in mach so I can't use hardware.

The Boxford speed control is also set by serial commands these I will attach to the relevant macro, the spindle speed is reported back by serial @ once a second but as I have already interfaced the spindle read to Mach so it is not that important.

I have the initialise script written, however this does not yet check that the initialisation has already been done, I dropped the messages as they pop up even before the macro is run?

*****************************************************************************************

Sub intialise_boxford() ' Boxford Duet1 9600 8 data 1 stop even parity

'******************************** file send routine *****************************
message "Initialising Boxford"
Open "c:\mach3\duet.dat" For Input As #1 ' Open file.
Do While Not EOF(1) ' Loop until end of file.
outint = Asc(Input (1,#1)) ' Read value into variable.
loop_1: If (getportbyte(1021) And 32)<>0  Then   'Line Status Register bit 5 TX holding reg empty
putportbyte(1016,outint) 'This is the TX register
Else
GoTo loop_1
End If
Loop
message "Boxford Initialised"
playwave "c:\tada.wav"
Close #1 ' Close file.
'***********************************************************************************
End Sub


**** The read macro looks at the momment like this it's saving to a file so I can see the results


***************************************************************
' This works and reads just the available serial byte received

Open "c:\mach3\Dout.dat" For Output As #1 ' Open file.

For i = 1 To 10000
If (getportbyte(1021) And 1) <> 0 Then ' receive status register
inbyte = getportbyte(1016)
Print #1,inbyte
End If
Next i

*************************************************************

Thanks Again