Machsupport Forum

Mach Discussion => General Mach Discussion => Topic started by: davidimurray on March 25, 2006, 12:43:54 PM

Title: Serial Toolchanger Macro
Post by: davidimurray on March 25, 2006, 12:43:54 PM
Hi

I was wondering if someone could help me. I'm working on the electronics for a friends lathe toolchanger. Using an Atmel AVR micro-controller, I've produced a board that accepts the tool number in the form of t1d, t2d etc with a CR on the end over a serial link. The tool is changed and once complete, the toolchanger sends back a t1s, t2s etc to show that the change is complete and the correct tool is selected.

I've written a macro that sends the code to the electronics and performs the toolchange. However I can't seem to get the serial input back in to work. I tried using getfifo entry in a while loop such that when getfifoentry does not = "none" it should leave the loop and enter the next section of code. However the code seems to get stuck in the while loop. Anyone have any ideas?

Cheers

Dave
Title: Re: Serial Toolchanger Macro
Post by: Graham Waterworth on March 25, 2006, 12:55:20 PM
Hi,

Are you getting anything back at all?

Are you using handshaking?

If you want you can send me the macro and I will take a look at it.

Graham.
Title: Re: Serial Toolchanger Macro
Post by: davidimurray on March 25, 2006, 02:33:47 PM
Hi Graham

The electronics have worked both with the terminal emulator in the AVR software and in Hyperterminal so I know that the electronics side seems to be working ok. Transmitting codes to the electronics seem to work fine as well. There is no handshaking invovled, it is a simple two-wire RS232 connection with CR at the end of each line.

I've included part of the coden note that i've used the message to help with debugging - Currently only setup for tool 1 as I want to try and fix one set of code before I copy it along for each tool :-

Code: [Select]
tool = GetSelectedTool()
' Max number of tools

num_positions = 8 

' do not allow tool number greater than number of turret positions

While tool > num_positions Or tool < 1
Tool = Question ("Invalid Tool Requested, New Tool Number?")
Wend


Select Case tool

Case 1
message "Changing To Tool 1"
Call sendserial ("t1d" & Chr(13))

While getfifoentry() = "None"
message getfifoentry
Wend

if getfifoentry() = "t1s" & Chr(13) then
message "Tool 1 Selected"
SetCurrentTool( tool )
End select
else
Message "Tool Change Error"
end if



Case 2
message "Changing To Tool 2"
Call sendserial ("t2d" & Chr(13))

Case 3
message "Changing To Tool 3"
Call sendserial ("t2d" & Chr(13))

End Select

I will warn you that this is the first macro I have written for Mach so its probably some simple mistake!

Thanks for your help.

Cheers

Dave
Title: Re: Serial Toolchanger Macro
Post by: Graham Waterworth on March 25, 2006, 05:56:00 PM
Hi Dave,

Look at comment below in the code.

What version of Mach are you using?

Older versions of Mach3 needed CR+LF on getfifoentry(), I think Art was going to change it at one point,  it may be worth trying if you can change your output from the toolchange code. It may still be on the to do list.

Thanks

Graham

Select Case tool

Case 1
message "Changing To Tool 1"
Call sendserial ("t1d" & Chr(13))

(what are you getting with this bit below, is it showing any characters, if so the next call to getfifoentry() will be empty)

While getfifoentry() = "None" (what about a & Chr(13) here)
message getfifoentry
Wend

if getfifoentry() = "t1s" & Chr(13)  then
message "Tool 1 Selected"
SetCurrentTool( tool )
End select
else
Message "Tool Change Error"
end if
Title: Re: Serial Toolchanger Macro
Post by: davidimurray on March 26, 2006, 12:01:28 PM
Hi Graham

This section always seem to shows 'None'. Is there a wait to put a timed delay in ? I was wondering if I could put a 5 second loop in the program, in case the loop is updating faster than message can keep up.

I'm using V1.9*********xx. I used some software a while ago that gave me the serial input in the form of hex so I will try and dig this out to check that a CR is being sent. I ha a look through the yahoo list and I think Art had now changed it to support CR+LF and CR. Just got back from the workshop so I will have another look in the next few days - new Acme screw ready to go on my mill!!! And i'm in the middle of fitting up the spindle control for the mill, and this toolchanger for a friend, and must get round to doing some more on my two steam engines. Hmmmmm - you can never have enough jobs on the go at once!!!

Cheers

Dave
Title: Re: Serial Toolchanger Macro
Post by: davidimurray on March 27, 2006, 04:20:48 PM
Hmmm

Now I'm confused. Just ran a test using serial monitor to look at the input and output using both Hyperterminal and Mach. Here are the results in the attached screen dump. As you can see, the electronics actually return a CR and LF. The problem seems to be that Mach doesn't seem to be opening the port. Anybody got any ideas?

Cheers

Dave

(http://www.geocities.com/davidimurray/serialmonitor.JPG)