Re: [Emc-users] Serial Port access

2021-09-13 Thread John Dammeyer
> From: Gene Heskett [mailto:ghesk...@shentel.net]
> On Monday 13 September 2021 18:11:44 John Dammeyer wrote:
> 
> > Hi Gene,
> > I was able to use your pyvcp information along with the web documents
> > to get my own slider working. In the CAN message screen grab you can
> > see id=218, dlc=4, and the first two bytes representing 0x0032 in
> > Little Endian format.  That value in decimal is 50. Scale screen grab
> > shows the slider set at 50.  Drag the slider back and forth and the
> > CAN message changes. And on the scope the screen shot shows 5V.  Drag
> > the slider back and forth and the voltage trace changes amplitude.
> > That voltage is based on the received CANopen message sent from the
> > slider on the Pi4 LCNC. Thanks again for your help.
> > John Dammeyer
> >
> NP John, glad I could help.

I realized after I posted all that and looked at the PIC source code that I 
remembered incorrectly (ie. Forgot)  that the PWM values are 8 bits not 16 with 
a resolution of 1%.  Only two bytes are needed in the message.  The code below 
shows how it's properly converted and set into the hardware PWM generation 
registers.

  case 0x200 :  // Receive PDO 1
// PWM Outputs for LH CONN pin 2,11
if (id == NodeID ) {
OC3RS = ScalePWM((int)CANOpenMsg.d.data[0]);
OC4RS = ScalePWM((int)CANOpenMsg.d.data[1]);
ObjectDictionaryValues[XIM_PWM1_NDX] = ReportPWM(0);
ObjectDictionaryValues[XIM_PWM2_NDX] = ReportPWM(1);
}
break;


> 
> Cheers, Gene Heskett
> --
> "There are four boxes to be used in defense of liberty:
>  soap, ballot, jury, and ammo. Please use in that order."
> -Ed Howdershelt (Author)
> If we desire respect for the law, we must first make the law respectable.
>  - Louis D. Brandeis
> Genes Web page 
> 
> 
> ___
> Emc-users mailing list
> Emc-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/emc-users



___
Emc-users mailing list
Emc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-users


Re: [Emc-users] Serial Port access

2021-09-13 Thread Gene Heskett
On Monday 13 September 2021 18:11:44 John Dammeyer wrote:

> Hi Gene,
> I was able to use your pyvcp information along with the web documents
> to get my own slider working. In the CAN message screen grab you can
> see id=218, dlc=4, and the first two bytes representing 0x0032 in
> Little Endian format.  That value in decimal is 50. Scale screen grab
> shows the slider set at 50.  Drag the slider back and forth and the
> CAN message changes. And on the scope the screen shot shows 5V.  Drag
> the slider back and forth and the voltage trace changes amplitude. 
> That voltage is based on the received CANopen message sent from the
> slider on the Pi4 LCNC. Thanks again for your help.
> John Dammeyer
>
NP John, glad I could help.

Take care now.

Cheers, Gene Heskett
-- 
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
If we desire respect for the law, we must first make the law respectable.
 - Louis D. Brandeis
Genes Web page 


___
Emc-users mailing list
Emc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-users


Re: [Emc-users] Serial Port access

2021-09-13 Thread John Dammeyer
Hi Gene,
I was able to use your pyvcp information along with the web documents to get my 
own slider working.
In the CAN message screen grab you can see id=218, dlc=4, and the first two 
bytes representing 0x0032 in Little Endian format.  That value in decimal is 50.
Scale screen grab shows the slider set at 50.  Drag the slider back and forth 
and the CAN message changes.
And on the scope the screen shot shows 5V.  Drag the slider back and forth and 
the voltage trace changes amplitude.  That voltage is based on the received 
CANopen message sent from the slider on the Pi4 LCNC.
Thanks again for your help.
John Dammeyer

> -Original Message-
> From: Gene Heskett [mailto:ghesk...@shentel.net]
> Piece of cake John, the pyvcp .xml file snippet that draws them:
> but there's a wagon load of stuff above it too. :o)

___
Emc-users mailing list
Emc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-users


Re: [Emc-users] Serial Port access

2021-09-12 Thread John Dammeyer
In order to improve my rather poor Python skills I've spent the last day 
fighting with Python 3 Thonny on my WIN-10 laptop.  The issue is the change 
from Python 2 to 3 to handle extended characters which a small module like the 
CANUSB has no knowledge of.  So dealing with 0x07 (bell character) and 0x0D (CR 
character) requires strange statements like 

# Initialize CANUSB dongle
ser.eol = '\r'.encode('utf-8')
ser.write('C\r'.encode('utf-8'))# Close first
ser.write('F\r'.encode('utf-8'))# Clear Error Flags by reading them
ser.write('S5\r'.encode('utf-8'))   # set 250kbps
ser.write('O\r'.encode('utf-8'))# Open CANUSB for communication.

Received data requires the same hoops.  Anyway, I think I have a simple 
character accumulation and parsing program working that now sends a message to 
toggle an output and moves the CANopen node reporting NMT PRE-OP status into 
OPERATIONAL a which point it starts sending PDO messages with status.

This is not a LinuxCNC Python program.  That one works fine setting say MIST 
COOLANT ON/OFF via the AXIS screen button.  This parsing of messages etc is 
designed to get data back from a CANopen module into LinuxCNC when I move it to 
the LinuxCNC version.

Anyway attached is the output showing the messages and how the module comes on 
line.  I'll post the code when I've ported it to the LinuxCNC version.

John Dammeyer




> -Original Message-
> From: John Dammeyer [mailto:jo...@autoartisans.com]
> Sent: September-10-21 10:11 AM
> To: 'Enhanced Machine Controller (EMC)'
> Subject: Re: [Emc-users] Serial Port access
> 
> Hi Andy,
> 
> The output below shows CANopen PDO message #2 (0x300) to ID 0x18, 1 byte, 
> alternating between 0x01 and 0x00 being issued once
> per second.
> 
> pi@raspberrypi:~/projects/python $ python TestSerial.py
> Sent CAN message with relay value = t318101
> Sent CAN message with relay value = t318100
> Sent CAN message with relay value = t318101
> Sent CAN message with relay value = t318100
> Sent CAN message with relay value = t318101
> 
> The little module shown in that photo I posted last time is connected to a 
> pneumatic valve on Output #1.  It clicks ON and OFF once
> per second.   The code is running as a Python Command line program on a 
> standard Raspian distro.  I'll bring out the Pi4 with
> LinuxCNC and take a look at linking into the HAL file.
> 
> IMHO the Python serial is very clumsy for dealing with serial with all the 
> format and .encode parameters for simple character strings.
> The source code is attached.
> 
> John Dammeyer
> 
> > From: andy pugh [mailto:bodge...@gmail.com]
> > On Thu, 9 Sept 2021 at 05:31, John Dammeyer < 
> > <mailto:jo...@autoartisans.com> jo...@autoartisans.com> wrote:
> > > I've been reading
> > >  <http://linuxcnc.org/docs/2.4/html/hal_comp.html> 
> > > http://linuxcnc.org/docs/2.4/html/hal_comp.html
> >
> > For this application I think that a Python userspace component using
> > Pyserial is probably the easier approach.
> >
> >  <http://linuxcnc.org/docs/2.8/html/hal/halmodule.html> 
> > http://linuxcnc.org/docs/2.8/html/hal/halmodule.html
> >
> > --
> > atp


PythonCAN-1.pdf
Description: Adobe PDF document
___
Emc-users mailing list
Emc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-users


Re: [Emc-users] Serial Port access

2021-09-11 Thread Gene Heskett
On Saturday 11 September 2021 13:33:30 John Dammeyer wrote:

> Hi Gene,
> On Vancouver Island so other end of the country and about 4 days by
> road if one is not driving 24/7.
>
> Thanks for the code fragment.  Very helpful.
>
> I do have two buttons
>
> #  Tag buttons 
> net remote-rapid-to-Z-home halui.mdi-command-16 <=
> pyvcp.rapid-to-Z-home net remote-rapid-to-XY-home halui.mdi-command-17
> <= pyvcp.rapid-to-XY-home
>
> And they are coupled to the system in the .INI file along with the
> pendant buttons as #16 and #17 in the list to create the G-Code for
> motion.
>
> [HALUI]
> # These are the commands for the HB04 and PyVCP screen buttons.
> # a halui hal pin is created for each MDI_COMMAND below
> # halui.mdi-command-00, halui.mdi-command-01,... etc
> #
> MDI_COMMAND=G0 X0 Y0 Z0
> MDI_COMMAND=(debug, example: mdi-01)
> MDI_COMMAND=(debug, example: mdi-02)
> #03 M110: clears notifications
> MDI_COMMAND=M110
> MDI_COMMAND=(debug, example: mdi-04)
> MDI_COMMAND=(debug, example: mdi-05)
> MDI_COMMAND=(debug, example: mdi-06)
> #07 M101: example print to stdout
> MDI_COMMAND=M101
> MDI_COMMAND=(debug, example: mdi-08)
> MDI_COMMAND=(debug, example: mdi-09)
> MDI_COMMAND=(debug, example: mdi-10)
> MDI_COMMAND=(debug, example: mdi-11)
> #12 Set current physical X position to be 0
> MDI_COMMAND= G10 L20 P0 X0
> #13 Set current physical Y position to be 0
> MDI_COMMAND= G10 L20 P0 Y0
> #14 Set current physical Z position to be 0
> MDI_COMMAND= G10 L20 P0 Z0
> #15 Set current physical A position to be 0
> MDI_COMMAND= G10 L20 P0 A0
> # 16 pyVCP button Full speed to Z0
> MDI_COMMAND= G0 Z0
> MDI_COMMAND= G0 X0 Y0
>
> If I understand the HAL file code then your mister is totally
> controlled by the slider.  No simple button for ON/OFF?

On/Off is the mister checkmark. Perhaps my grepping failed?
try this:
gene@sixty40:~/linuxcnc/configs/6040-5i25-7i76-rs485$ grep mist *
6040-5i25-7i76-rs485.hal:loadrt xor2 count=2 #2nd one is mist-ctl
6040-5i25-7i76-rs485.hal:loadrt and2 names=and-prb1,and-prb2,mist-ctl
6040-5i25-7i76-rs485.hal:addf  xor2.1servo-thread # turns mister on/off
6040-5i25-7i76-rs485.hal:addf  timedelay.3   servo-thread # mist oscillator
6040-5i25-7i76-rs485.hal:# output for coolant-mist air ctrl - WORKS! Valve coil 
gets HOT
6040-5i25-7i76-rs485.hal:net mist-on <= iocontrol.0.coolant-mist => 
hm2_5i25.0.7i76.0.0.output-01 <--this one?
6040-5i25-7i76-rs485.hal:# turns on tool mister air valv, and supplies pump 12 
volts
6040-5i25-7i76-rs485.hal:net mist-on => xor2.1.in0  # turn on pump motor speed 
control
6040-5i25-7i76-rs485.hal:net mister-out  <= timedelay.3.out => xor2.1.in1
6040-5i25-7i76-rs485.hal:net mister-out  => hm2_5i25.0.gpio.024.out # to pump 
pwr control

That whole thing:

#***
# output for coolant-mist air ctrl - WORKS! Valve coil gets HOT
net mist-on <= iocontrol.0.coolant-mist => hm2_5i25.0.7i76.0.0.output-01
# turns on tool mister air valv, and supplies pump 12 volts
net mist-on => xor2.1.in0  # turn on pump motor speed control
net osc-fdbck  <= xor2.1.out => timedelay.3.in # make speed timer oscillator
setp hm2_5i25.0.gpio.024.is_output true
net mister-out  <= timedelay.3.out => xor2.1.in1
net mister-out  => hm2_5i25.0.gpio.024.out # to pump pwr control
# note, get pump power from output of relay driven by 1st line above.
# Otherwise pump runs when lcnc off/ stopped/shut down
#***

that should help.

Take care, John
> > Note too, that depending on what else you already have in the .hal
> > file, the .number. may change.

Cheers, Gene Heskett
-- 
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
If we desire respect for the law, we must first make the law respectable.
 - Louis D. Brandeis
Genes Web page 


___
Emc-users mailing list
Emc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-users


Re: [Emc-users] Serial Port access

2021-09-11 Thread John Dammeyer
Hi Gene,
On Vancouver Island so other end of the country and about 4 days by road if one 
is not driving 24/7.

Thanks for the code fragment.  Very helpful.

I do have two buttons

#  Tag buttons 
net remote-rapid-to-Z-home halui.mdi-command-16 <= pyvcp.rapid-to-Z-home
net remote-rapid-to-XY-home halui.mdi-command-17 <= pyvcp.rapid-to-XY-home

And they are coupled to the system in the .INI file along with the pendant 
buttons as #16 and #17 in the list to create the G-Code for motion.

[HALUI]
# These are the commands for the HB04 and PyVCP screen buttons.
# a halui hal pin is created for each MDI_COMMAND below
# halui.mdi-command-00, halui.mdi-command-01,... etc
# 
MDI_COMMAND=G0 X0 Y0 Z0
MDI_COMMAND=(debug, example: mdi-01)
MDI_COMMAND=(debug, example: mdi-02)
#03 M110: clears notifications
MDI_COMMAND=M110
MDI_COMMAND=(debug, example: mdi-04)
MDI_COMMAND=(debug, example: mdi-05)
MDI_COMMAND=(debug, example: mdi-06)
#07 M101: example print to stdout
MDI_COMMAND=M101
MDI_COMMAND=(debug, example: mdi-08)
MDI_COMMAND=(debug, example: mdi-09)
MDI_COMMAND=(debug, example: mdi-10)
MDI_COMMAND=(debug, example: mdi-11)
#12 Set current physical X position to be 0
MDI_COMMAND= G10 L20 P0 X0
#13 Set current physical Y position to be 0
MDI_COMMAND= G10 L20 P0 Y0
#14 Set current physical Z position to be 0
MDI_COMMAND= G10 L20 P0 Z0
#15 Set current physical A position to be 0
MDI_COMMAND= G10 L20 P0 A0
# 16 pyVCP button Full speed to Z0
MDI_COMMAND= G0 Z0
MDI_COMMAND= G0 X0 Y0

If I understand the HAL file code then your mister is totally controlled by the 
slider.  No simple button for ON/OFF?

John


> -Original Message-
> From: Gene Heskett [mailto:ghesk...@shentel.net]
> Sent: September-11-21 7:01 AM
> To: emc-users@lists.sourceforge.net
> Subject: Re: [Emc-users] Serial Port access
> 
> On Saturday 11 September 2021 05:02:47 John Dammeyer wrote:
> 

> > I'm still waiting for mine to arrive.  Latest is that it arrived at
> > Canada Post in Toronto.  I'm going to guess it's going via surface
> > from there to here.  So another week.
> 
> I take it you are sorta out in the toulies then? I got mine from ebay,
> bought 4 of them knowing the limited lifetime of the silicon hose the
> the pump squeezes with rollers. Its now been close to 2 years & about a
> gallon of koolmist thru it, and 3 of them are still in the bag. About $9
> usd a copy on ebay.

> But that was then, now I'll be 87 in a couple weeks. And alone again.
> 

You're more than 20 years further along on this than I am.


> > Not sure how to do sliders yet on the AXIS interface.
> 
> Piece of cake John, the pyvcp .xml file snippet that draws them:
> but there's a wagon load of stuff above it too. :o)
> 
>   
> 
>   
> 
>   ("5")
>   "mist-on-adj"
>   .000
>   .025
>   .005
>   0.001
>   ".3f"
>   ("Helvitica",12)
>   0
> 
> 
>   ("5")
>   "mist-off-adj"
>   .000
>   .250
>   .100
>   0.001
>   ".3f"
>   ("Helvitica",12)
>   0
> 
>   
> 
>   
> ==
> then in postgui.hal:
> 
> # for mister pump motor speed ctrl
> net mister-spdon<= pyvcp.mist-on-adj  => timedelay.3.off-delay
> net mister-spdoff   <= pyvcp.mist-off-adj => timedelay.3.on-delay
> 
> then in the main.hal:
> 
> 6040-5i25-7i76-rs485.hal:addf  xor2.1servo-thread
> # turns mister on/off
> 6040-5i25-7i76-rs485.hal:net mist-on => xor2.1.in0
> # turn on pump motor speed control
> 6040-5i25-7i76-rs485.hal:net osc-fdbck  <= xor2.1.out => timedelay.3.in
> # make speed timer oscillator
> 6040-5i25-7i76-rs485.hal:net mister-out  <= timedelay.3.out => xor2.1.in1
> 
> and:
> 
> loadrt timedelaycount=4 #.3 is mist motor timer
> loadrt xor2 count=2 #.1 one is mist-ctl
> 6040-5i25-7i76-rs485.hal:addf  timedelay.3  servo-thread
> # is mist oscillator
> 6040-5i25-7i76-rs485.hal:net osc-fdbck  <= xor2.1.out => timedelay.3.in
> # make speed timer oscillator
> 6040-5i25-7i76-rs485.hal:net mister-out  <= timedelay.3.out => xor2.1.in1
> 
> The xor2.1 is the on-off switch for te oscillator, interrupting the
> feedback path when the mist button is off
> 
> Note too, that depending on what else you already have in the .hal file,
> the .number. may change.
> 



___
Emc-users mailing list
Emc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-users


Re: [Emc-users] Serial Port access

2021-09-11 Thread Gene Heskett
On Saturday 11 September 2021 05:02:47 John Dammeyer wrote:

> Hi Gene,
> Hi Gene,
>
> > I don't know much about the CAN bus, but this does sound like a
> > howto to do a relay.
>
> I'm working on the input side of things next.
>
> > But I went a different path as I am using a peristaltic pump that
> > has a std brushed motor to drive the pump. A positive displacement
> > pump quite similar to whats used at the hospital for IV drips.
>
> I'm still waiting for mine to arrive.  Latest is that it arrived at
> Canada Post in Toronto.  I'm going to guess it's going via surface
> from there to here.  So another week.

I take it you are sorta out in the toulies then? I got mine from ebay, 
bought 4 of them knowing the limited lifetime of the silicon hose the 
the pump squeezes with rollers. Its now been close to 2 years & about a 
gallon of koolmist thru it, and 3 of them are still in the bag. About $9 
usd a copy on ebay.
>
> > But the pump ran way too fast and could drain an 8oz coke bottle of
> > koolmist mix in a couple minutes, flooding the work area which had
> > no drainage or waste recovery provisions on my 6040 mill.  So I
> > setup a timer in hal to generate a variable rate PWM like signal I
> > could send to the pumps power transistor. By turning the pump on for
> > around 5 ms, and off for 250 ms, I get just enough mist to keep the
> > tool cool when that teeny pulse of the pump is pushed to the
> > workface with 3 or so lbs of air pressure with that air valve
> > controlled by the same bit that enables the pwm oscillator for the
> > motor. And I've pyvcp sliders in the gui to control how wet the
> > spray is. Now I've been looking for a suitable air pump to drive the
> > atomizer since regulators don't do well at the desired air flows and
> > it heats the shop compressor needlessly.
>
> I've gone the pressurized method with a small needle valve to regulate
> the flow and 5PSI to pressurize the reservoir.

Finding a quality needle valve is quite a challenge.

I did similar in version .001 but I didn't have adequate control, so the 
plastic coke bottle is no longer pressurized in version .01.  The pump 
is straped to the gantry riser above the little shelf the coke bottle 
sits on with a broom handle hanger loop dropped over the top of the 
bottle so if Y jerks, the bottle has to follow.

If idle for weeks, it might lose prime, but catches up and fills the weed 
eater fuel hose (that stuffs expensive) to the nozzle in around a 
minute, quicker if I speed up the motor. Sorta complex but suits my 
needs well.

I've considered doing that on the other machines but would need to 
recycle the drainage better. That plus I'd druther not get cast iron 
wet. Koolmist is wetter than water and carry's the way lube away.  
Somewhat Like a mild photoflow that was used in a chemical darkroom 
before digital cameras took over 40 years ago.

I used to do that too, in a past life, even formulated my own color print 
developer that didn't fade sitting in the warm bath for 4 hours. My 
stuff could make 8 identical 8x10 wedding photos in a row, all at the 
same filter settings on the enlarger. Commercial mix couldn't do that, 
it faded too fast.

But that was then, now I'll be 87 in a couple weeks. And alone again.

> But if there are 
> issues I will have a pump to do what you are doing.  However, I'll use
> the same module I'm using for the power draw bar.  It has PWM 0-10V
> capabilities so I can include the PWM value with the relay values.
>
> Not sure how to do sliders yet on the AXIS interface.

Piece of cake John, the pyvcp .xml file snippet that draws them:
but there's a wagon load of stuff above it too. :o)

  

  

  ("5")
  "mist-on-adj"
  .000
  .025
  .005
  0.001
  ".3f"
  ("Helvitica",12)
  0


  ("5")
  "mist-off-adj"
  .000
  .250
  .100
  0.001
  ".3f"
  ("Helvitica",12)
  0

  

  
==
then in postgui.hal:

# for mister pump motor speed ctrl
net mister-spdon<= pyvcp.mist-on-adj  => timedelay.3.off-delay
net mister-spdoff   <= pyvcp.mist-off-adj => timedelay.3.on-delay

then in the main.hal:

6040-5i25-7i76-rs485.hal:addf  xor2.1servo-thread
# turns mister on/off
6040-5i25-7i76-rs485.hal:net mist-on => xor2.1.in0
# turn on pump motor speed control
6040-5i25-7i76-rs485.hal:net osc-fdbck  <= xor2.1.out => timedelay.3.in
# make speed timer oscillator
6040-5i25-7i76-rs485.hal:net mister-out  <= timedelay.3.out => xor2.1.in1

and:

loadrt timedelaycount=4 #.3 is mist motor timer
loadrt xor2 count=2 #.1 one is mist-ctl
6040-5i25-7i76-rs485.hal:addf  timedelay.3  servo-thread 
# is mist oscillator

Re: [Emc-users] Serial Port access

2021-09-11 Thread John Dammeyer
Hi Gene,
Hi Gene,
> 
> I don't know much about the CAN bus, but this does sound like a howto to
> do a relay.

I'm working on the input side of things next.  
> 
> But I went a different path as I am using a peristaltic pump that has a
> std brushed motor to drive the pump. A positive displacement pump quite
> similar to whats used at the hospital for IV drips.

I'm still waiting for mine to arrive.  Latest is that it arrived at Canada Post 
in Toronto.  I'm going to guess it's going via surface from there to here.  So 
another week.

> 
> But the pump ran way too fast and could drain an 8oz coke bottle of
> koolmist mix in a couple minutes, flooding the work area which had no
> drainage or waste recovery provisions on my 6040 mill.  So I setup a
> timer in hal to generate a variable rate PWM like signal I could send to
> the pumps power transistor. By turning the pump on for around 5 ms, and
> off for 250 ms, I get just enough mist to keep the tool cool when that
> teeny pulse of the pump is pushed to the workface with 3 or so lbs of
> air pressure with that air valve controlled by the same bit that enables
> the pwm oscillator for the motor. And I've pyvcp sliders in the gui to
> control how wet the spray is. Now I've been looking for a suitable air
> pump to drive the atomizer since regulators don't do well at the desired
> air flows and it heats the shop compressor needlessly.

I've gone the pressurized method with a small needle valve to regulate the flow 
and 5PSI to pressurize the reservoir.  But if there are issues I will have a 
pump to do what you are doing.  However, I'll use the same module I'm using for 
the power draw bar.  It has PWM 0-10V capabilities so I can include the PWM 
value with the relay values.

Not sure how to do sliders yet on the AXIS interface.  And I will continue to 
post the code as it develops.  I'm already up to Rev 0.2 now.  Moved the read 
routine outside the send routine as it was in the original serial code.   The 
CANUSB would signal buffer overruns because unless one of the outputs changed 
the function might not be called for hours.

More as things progress.
John

> 
> I cut out a couple chuck wrenches from 1/2" thick alu plate, one to fit
> that spindle motors double flatted shaft and one to fit the ER nut, on
> half of that 8oz bottle of koolmist. And that was almost too much.
> 
> But it added to linuxcnc's job by making it do the pump timing. It does
> it, but I would have preferred to put that timing on the end of a cable
> that only had to be updated when the desired status changed. I think
> this might be the method I would have used had it been available 2 years
> ago, so thank you John. I believe you have added to linuxcnc's
> capabilities.
> 
> > > -Original Message-
> > > From: John Dammeyer [mailto:jo...@autoartisans.com]
> > > Sent: September-10-21 10:11 AM
> > > To: 'Enhanced Machine Controller (EMC)'
> > > Subject: Re: [Emc-users] Serial Port access
> > >
> > > Hi Andy,
> > >
> > > The output below shows CANopen PDO message #2 (0x300) to ID 0x18, 1
> > > byte, alternating between 0x01 and 0x00 being issued once per
> > > second.
> > >
> > > pi@raspberrypi:~/projects/python $ python TestSerial.py
> > > Sent CAN message with relay value = t318101
> > > Sent CAN message with relay value = t318100
> > > Sent CAN message with relay value = t318101
> > > Sent CAN message with relay value = t318100
> > > Sent CAN message with relay value = t318101
> > >
> > > The little module shown in that photo I posted last time is
> > > connected to a pneumatic valve on Output #1.  It clicks ON and OFF
> > > once per second.   The code is running as a Python Command line
> > > program on a standard Raspian distro.  I'll bring out the Pi4 with
> > > LinuxCNC and take a look at linking into the HAL file.
> > >
> > > IMHO the Python serial is very clumsy for dealing with serial with
> > > all the format and .encode parameters for simple character strings.
> > > The source code is attached.
> > >
> > > John Dammeyer
> > >
> > > > From: andy pugh [mailto:bodge...@gmail.com]
> > > >
> > > > On Thu, 9 Sept 2021 at 05:31, John Dammeyer <
> <mailto:jo...@autoartisans.com> jo...@autoartisans.com> wrote:
> > > > > I've been reading
> > > > >  <http://linuxcnc.org/docs/2.4/html/hal_comp.html>
> > > > > http://linuxcnc.org/docs/2.4/html/hal_comp.html
> > > >
> > > > For this application I think that a Python userspace component
> > > > using Pyserial is probab

Re: [Emc-users] Serial Port access

2021-09-11 Thread Gene Heskett
On Saturday 11 September 2021 00:52:26 John Dammeyer wrote:

> So a bit more news.  Good news!
>
> The attached screen shot from the RM CAN monitor shows 3 messages. 
> The first message with ID 0x298 is a PDO message which is the status
> from the device.  Second byte lower 4 bits represents what it says the
> outputs are set to.  The top 4 bits are what it was commanded to do
> with those outputs.
>
> The next message is the NMT heartbeat from node 0x718 which is my
> device.  The 0x05 says its alive and NMT_OPERATIONAL which means it's
> allowed to send PDO messages with device information.
>
> Finally we have the PDO message 0x318 which is 'from' the Pi4 LinuxCNC
> interfaced to the Lawicel CANUSB as /dev/ttyUSB0 using the Python
> pySerial library.
>
> Notice the 0x04 data byte.  That's the bit which is connected to the
> Mist ON/OFF button and that bit switches on a relay in my little
> device.
>
> Also attached is the python file.  I put the HAL stuff in the
> custom.hal file.
>
> I click on the checkbox on the Axis interface and the mist relay
> clicks on.  Click again to remove the checkmark and the mist relay
> goes off.  And the PDO message on the monitor goes from 00 to 04 to
> 00.
>
> This example is the sending from AXIS via pySerial onto the CAN bus. 
> Next step will be to present a switch press that is read by my device
> and shows up in the first byte of the 0x298 PDO.  And I guess I'll add
> a heartbeat from LinuxCNC..
>
> Lots more to do but at this point I can control relays via CAN bus.
>
> John Dammeyer

I don't know much about the CAN bus, but this does sound like a howto to 
do a relay.

But I went a different path as I am using a peristaltic pump that has a 
std brushed motor to drive the pump. A positive displacement pump quite 
similar to whats used at the hospital for IV drips.

But the pump ran way too fast and could drain an 8oz coke bottle of 
koolmist mix in a couple minutes, flooding the work area which had no 
drainage or waste recovery provisions on my 6040 mill.  So I setup a 
timer in hal to generate a variable rate PWM like signal I could send to 
the pumps power transistor. By turning the pump on for around 5 ms, and 
off for 250 ms, I get just enough mist to keep the tool cool when that 
teeny pulse of the pump is pushed to the workface with 3 or so lbs of 
air pressure with that air valve controlled by the same bit that enables 
the pwm oscillator for the motor. And I've pyvcp sliders in the gui to 
control how wet the spray is. Now I've been looking for a suitable air 
pump to drive the atomizer since regulators don't do well at the desired 
air flows and it heats the shop compressor needlessly.

I cut out a couple chuck wrenches from 1/2" thick alu plate, one to fit 
that spindle motors double flatted shaft and one to fit the ER nut, on 
half of that 8oz bottle of koolmist. And that was almost too much.

But it added to linuxcnc's job by making it do the pump timing. It does 
it, but I would have preferred to put that timing on the end of a cable 
that only had to be updated when the desired status changed. I think 
this might be the method I would have used had it been available 2 years 
ago, so thank you John. I believe you have added to linuxcnc's 
capabilities.

> > -Original Message-
> > From: John Dammeyer [mailto:jo...@autoartisans.com]
> > Sent: September-10-21 10:11 AM
> > To: 'Enhanced Machine Controller (EMC)'
> > Subject: Re: [Emc-users] Serial Port access
> >
> > Hi Andy,
> >
> > The output below shows CANopen PDO message #2 (0x300) to ID 0x18, 1
> > byte, alternating between 0x01 and 0x00 being issued once per
> > second.
> >
> > pi@raspberrypi:~/projects/python $ python TestSerial.py
> > Sent CAN message with relay value = t318101
> > Sent CAN message with relay value = t318100
> > Sent CAN message with relay value = t318101
> > Sent CAN message with relay value = t318100
> > Sent CAN message with relay value = t318101
> >
> > The little module shown in that photo I posted last time is
> > connected to a pneumatic valve on Output #1.  It clicks ON and OFF
> > once per second.   The code is running as a Python Command line
> > program on a standard Raspian distro.  I'll bring out the Pi4 with
> > LinuxCNC and take a look at linking into the HAL file.
> >
> > IMHO the Python serial is very clumsy for dealing with serial with
> > all the format and .encode parameters for simple character strings.
> > The source code is attached.
> >
> > John Dammeyer
> >
> > > From: andy pugh [mailto:bodge...@gmail.com]
> > >
> > > On Thu, 9 Sept 2021 at 05:31, John Dammeyer < 
<mailto:jo...@autoartisans.com> jo...@autoartisan

Re: [Emc-users] Serial Port access

2021-09-10 Thread John Dammeyer
So a bit more news.  Good news!

The attached screen shot from the RM CAN monitor shows 3 messages.  The first 
message with ID 0x298 is a PDO message which is the status from the device.  
Second byte lower 4 bits represents what it says the outputs are set to.  The 
top 4 bits are what it was commanded to do with those outputs.

The next message is the NMT heartbeat from node 0x718 which is my device.  The 
0x05 says its alive and NMT_OPERATIONAL which means it's allowed to send PDO 
messages with device information.

Finally we have the PDO message 0x318 which is 'from' the Pi4 LinuxCNC 
interfaced to the Lawicel CANUSB as /dev/ttyUSB0 using the Python pySerial 
library.

Notice the 0x04 data byte.  That's the bit which is connected to the Mist 
ON/OFF button and that bit switches on a relay in my little device.

Also attached is the python file.  I put the HAL stuff in the custom.hal file.

I click on the checkbox on the Axis interface and the mist relay clicks on.  
Click again to remove the checkmark and the mist relay goes off.  And the PDO 
message on the monitor goes from 00 to 04 to 00.

This example is the sending from AXIS via pySerial onto the CAN bus.  Next step 
will be to present a switch press that is read by my device and shows up in the 
first byte of the 0x298 PDO.  And I guess I'll add a heartbeat from LinuxCNC..

Lots more to do but at this point I can control relays via CAN bus.

John Dammeyer

> -Original Message-
> From: John Dammeyer [mailto:jo...@autoartisans.com]
> Sent: September-10-21 10:11 AM
> To: 'Enhanced Machine Controller (EMC)'
> Subject: Re: [Emc-users] Serial Port access
> 
> Hi Andy,
> 
> The output below shows CANopen PDO message #2 (0x300) to ID 0x18, 1 byte, 
> alternating between 0x01 and 0x00 being issued once
> per second.
> 
> pi@raspberrypi:~/projects/python $ python TestSerial.py
> Sent CAN message with relay value = t318101
> Sent CAN message with relay value = t318100
> Sent CAN message with relay value = t318101
> Sent CAN message with relay value = t318100
> Sent CAN message with relay value = t318101
> 
> The little module shown in that photo I posted last time is connected to a 
> pneumatic valve on Output #1.  It clicks ON and OFF once
> per second.   The code is running as a Python Command line program on a 
> standard Raspian distro.  I'll bring out the Pi4 with
> LinuxCNC and take a look at linking into the HAL file.
> 
> IMHO the Python serial is very clumsy for dealing with serial with all the 
> format and .encode parameters for simple character strings.
> The source code is attached.
> 
> John Dammeyer
> 
> > From: andy pugh [mailto:bodge...@gmail.com]
> > On Thu, 9 Sept 2021 at 05:31, John Dammeyer < 
> > <mailto:jo...@autoartisans.com> jo...@autoartisans.com> wrote:
> > > I've been reading
> > >  <http://linuxcnc.org/docs/2.4/html/hal_comp.html> 
> > > http://linuxcnc.org/docs/2.4/html/hal_comp.html
> >
> > For this application I think that a Python userspace component using
> > Pyserial is probably the easier approach.
> >
> >  <http://linuxcnc.org/docs/2.8/html/hal/halmodule.html> 
> > http://linuxcnc.org/docs/2.8/html/hal/halmodule.html
> >
> > --
> > atp
#!/usr/bin/python

# Project LinuxCNC Python CANUSB Serial Port control derived from:
# 
https://forum.linuxcnc.org/10-advanced-configuration/538-controlling-coolant-w-serial-port?start=0
# User: mozmck  (Moses McKnight)

# This application has been modified to use the Lawicel CANUSB treated as a USB 
serial port
# sending out CAN messages in the CANopen format.

# Version 0.1 10SEP21
# Written by 
#   John Dammeyer
#   jo...@autoartisans.com

import hal
import time, serial

# *** Issue this command from the terminal
#sudo apt-get install python-serial

# The serial-relays.py needs to be in the config directory for your mill.
# For example:  '/home/jerrybaca/emc2/configs/harborfrieghtmill' 
# Don't forget to sudo chmod +x serial-relays.py

# *** Next Place the following lines into one of the Post HAL files.
# custom.hal is probably a good enough place.
#loadusr -Wn serial-relays ./serial-relays.py 

#net coolant-mist <= iocontrol.0.coolant-mist
#net coolant-flood <= iocontrol.0.coolant-flood

#net coolant-mist => serial-relays.relay1C
#net coolant-flood => serial-relays.relay1D
# *** End of HAL file instructions.

# --- Global Variables ---
h = hal.component("serial-relays")
h.newpin("relay1A", hal.HAL_BIT, hal.HAL_IN)
h.newpin("relay1B", hal.HAL_BIT, hal.HAL_IN)
h.newpin("relay1C", hal.HAL_BIT, hal.HAL_IN)
h.newpin("relay1D", hal.HAL_BIT, hal.HAL_IN)
h.newpin("relay1E", hal.HAL_BIT, hal.HAL_IN)
h.newpin("relay1F", hal.HAL_BIT, hal.HAL_IN)
h.newpin("relay1G", hal.HAL_BIT

Re: [Emc-users] Serial Port access

2021-09-10 Thread John Dammeyer
Hi Andy,
 
The output below shows CANopen PDO message #2 (0x300) to ID 0x18, 1 byte, 
alternating between 0x01 and 0x00 being issued once per second.
 
pi@raspberrypi:~/projects/python $ python TestSerial.py
Sent CAN message with relay value = t318101
Sent CAN message with relay value = t318100
Sent CAN message with relay value = t318101
Sent CAN message with relay value = t318100
Sent CAN message with relay value = t318101
 
The little module shown in that photo I posted last time is connected to a 
pneumatic valve on Output #1.  It clicks ON and OFF once per second.   The code 
is running as a Python Command line program on a standard Raspian distro.  I'll 
bring out the Pi4 with LinuxCNC and take a look at linking into the HAL file.
 
IMHO the Python serial is very clumsy for dealing with serial with all the 
format and .encode parameters for simple character strings.  The source code is 
attached.
 
John Dammeyer
 
> From: andy pugh [mailto:bodge...@gmail.com]
> On Thu, 9 Sept 2021 at 05:31, John Dammeyer <  
> jo...@autoartisans.com> wrote:
> > I've been reading
> >   
> > http://linuxcnc.org/docs/2.4/html/hal_comp.html
> 
> For this application I think that a Python userspace component using
> Pyserial is probably the easier approach.
> 
>   
> http://linuxcnc.org/docs/2.8/html/hal/halmodule.html
> 
> --
> atp
#!/usr/bin/python
# Test Application for CANUSB sending CANopen PDO #2 
# Version 0.1 10SEP21
# Written by 
#   John Dammeyer

import serial, time

# Serial stuff, change the serial port address by changing /dev/ttyS0 or COMx 
(for Windows)
# For USB based Serial dongles that use FTDI hardware /dev/ttyUSB0 is often the 
default.
# USB can be set for 115200 baud as long as the target hardware can support 
that since
# it doesn't really delay the LinuxCNC side.
ser = serial.Serial('/dev/ttyUSB0', 115200, bytesize=8, parity='N', stopbits=1, 
timeout=0, xonxoff=0, rtscts=0)

# Create some Global variables for readability
PDO = 0x300 # Process Data Object #2
NodeID = 0x18   # Device Node ID (0x01..0x7F)
PDO_ID = '' # The character string that holds the OR operation of the PDO+ID
RelayImage = 0  # No relays set yet.
CANopenPDOMsg = ''  # For reporting what we send and so we don't have to 
recreate it each time.
TempStr = ""# global so we can print what was sent.

# Function to send data to CANUSB dongle.  
# Parameters:
#   r is which relay to switch (1..8) 
#   does not validate relay # to see if in range.
#   level is TRUE or FALSE for relay ON or OFF.
# Outputs:
#   Sends CAN message to CANUSB.
#   Modifies Global RelayImage for control of more than one relay
#   Changes TempStr global variable for reporting message information.
def serial_command(r, level):
global RelayImage # if this isn't here then the OR operation fails 
with unitialized variable.
global TempStr# required so we can see what value was 
transmitted.
global CANopenPDOMsg  # the message without the data.

# Now empty the Rx Buffer for sample program we don't look at received 
messages.
while ser.inWaiting():
ser.reset_input_buffer()  #discard input for now.
 
# Create the text value of the relay image.
bitmask = 1 << (r-1)# Select which relay to switch ON.
if level == True:
RelayImage = (RelayImage | bitmask)
else:
RelayImage = (RelayImage &  ~bitmask)
ser.write(CANOpenPDOMsg.encode('utf-8'))  # send PDO 3xx to node 0x18 with 
1 byte
# Format bit image to two hex characters, add CR character which tells 
CANUSB to send CAN message.
TempStr = "{0:0{1}X}".format(RelayImage,2)
ser.write(TempStr.encode('utf-8'))
ser.write('\r'.encode('utf-8')) # Tell CANUSB to send message.

try:
# Create text value of PDO + ID
PDO_ID = "{0:0{1}X}".format(PDO+NodeID,3)
CANOpenPDOMsg = 't' + PDO_ID + '1'

# Initialize CANUSB dongle
ser.write('C\r'.encode('utf-8'))# Close first
ser.write('F\r'.encode('utf-8'))# Clear Error Flags by reading them
ser.write('S5\r'.encode('utf-8'))   # set 250kbps
ser.write('O\r'.encode('utf-8'))# Open CANUSB for communication.

# Main Loop
RelayValue = True
RelayNumber = 1
while 1:
serial_command(RelayNumber, RelayValue)
RelayValue = ~RelayValue
print("Sent CAN message with relay value = " + CANOpenPDOMsg + TempStr)
time.sleep(1)


except KeyboardInterrupt:
raise SystemExit___
Emc-users mailing list
Emc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-users


Re: [Emc-users] Serial Port access

2021-09-09 Thread John Dammeyer
> From: andy pugh [mailto:bodge...@gmail.com]
> 
> On Thu, 9 Sept 2021 at 05:31, John Dammeyer  wrote:
> 
> > I've been reading
> > http://linuxcnc.org/docs/2.4/html/hal_comp.html
> 
> For this application I think that a Pyhon userspace component using
> Pyserial is probably the easier approach.
> 
> http://linuxcnc.org/docs/2.8/html/hal/halmodule.html
> 
I did look at that document and saw the reference to pySerial at the bottom.  
First search last week didn’t really turn up anything.  This time from 2009 I 
found
https://forum.linuxcnc.org/10-advanced-configuration/538-controlling-coolant-w-serial-port

I'll put that into the Pi4 LinuxCNC and see if I can make it generate messages.

However I'm also still working on the .comp.  I've been editing and modifying 
"ArcEye arceyeATmgwareDOTcoDOTuk" serialcon2.comp

Thanks

Oh and my last posting on CANopen and LinuxCNC was back Sat, 27 Feb 2021 
10:12:25 -0800.  At that point I had done some things with the TI board and was 
working on a CANopen Lite version.  That project is on hold at the moment.  

I've since repurposed one of the projects I've done that has a dsPIC30F5011 and 
CAN bus with a CANopen Lite implementation.

The two buttons control pneumatic valves for Load/Release control of the 
drawbar.  The hall sensor counts socket revolutions so the R8 collet isn't 
dropped out with the TT Holder. Or press and hold the button and it turns 
continuously CW or CCW.  I can also send it a CAN message to do the same.

One of the DIP relays will run a different pneumatic solenoid for mist coolant 
so in the long run I'll want to connect that too. 

Baby steps.

John

___
Emc-users mailing list
Emc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-users


Re: [Emc-users] Serial Port access

2021-09-09 Thread andy pugh
On Thu, 9 Sept 2021 at 05:31, John Dammeyer  wrote:

> I've been reading
> http://linuxcnc.org/docs/2.4/html/hal_comp.html

For this application I think that a Pyhon userspace component using
Pyserial is probably the easier approach.

http://linuxcnc.org/docs/2.8/html/hal/halmodule.html

-- 
atp
"A motorcycle is a bicycle with a pandemonium attachment and is
designed for the especial use of mechanical geniuses, daredevils and
lunatics."
— George Fitch, Atlanta Constitution Newspaper, 1912


___
Emc-users mailing list
Emc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-users


Re: [Emc-users] Serial Port access

2021-09-08 Thread John Dammeyer
BTW, there's also this:
https://forum.linuxcnc.org/forum/18-computer/22562-arduino-based-usb-pendant-for-linuxcnc


> -Original Message-
> From: John Dammeyer [mailto:jo...@autoartisans.com]
> Sent: September-08-21 8:28 PM
> To: Enhanced Machine Controller (EMC)
> Subject: [Emc-users] Serial Port access
> 
> I'm starting the next phase of a small project.  I just about have the power 
> draw bar ready to mount.It's controlled by a small
> processor with two buttons for load and release which runs the air valves 
> which move the pneumatic cylinder and spin butterfly
> impact wrench.
> 
> To load/release from LinuxCNC I'd like to be able to put a couple of buttons 
> on the AXIS user interface.
> 
> The load button needs to create and send out a serial port the message 
> "t418102\r" and to release "t418104\r".  When AXIS first
> starts I'd also like to send out "C\r", "S5\r" and "O\r".  When AXIS closes 
> to send out a "O\r".  And obviously there has to be a way to
> select which serial port if there are a few.  (The one I want to use is USB 
> based).
> 
> In the long run I'd also like to be able to receive from the serial port.  
> Messages like "t718105\r" for example but that's not critical to
> start with.
> 
> I've been reading
> http://linuxcnc.org/docs/2.4/html/hal_comp.html
> 
> And I imagine there are a few other documents out there too.Is there a 
> simple tutorial for adding a button to the AXIS screen and
> having the button press generate a message out a serial port?
> 
> Thanks
> John
> 
> 
> ___
> Emc-users mailing list
> Emc-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/emc-users



___
Emc-users mailing list
Emc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-users


[Emc-users] Serial Port access

2021-09-08 Thread John Dammeyer
I'm starting the next phase of a small project.  I just about have the power 
draw bar ready to mount.It's controlled by a small processor with two 
buttons for load and release which runs the air valves which move the pneumatic 
cylinder and spin butterfly impact wrench.
 
To load/release from LinuxCNC I'd like to be able to put a couple of buttons on 
the AXIS user interface. 
 
The load button needs to create and send out a serial port the message 
"t418102\r" and to release "t418104\r".  When AXIS first starts I'd also like 
to send out "C\r", "S5\r" and "O\r".  When AXIS closes to send out a "O\r".  
And obviously there has to be a way to select which serial port if there are a 
few.  (The one I want to use is USB based).
 
In the long run I'd also like to be able to receive from the serial port.  
Messages like "t718105\r" for example but that's not critical to start with.
 
I've been reading 
http://linuxcnc.org/docs/2.4/html/hal_comp.html
 
And I imagine there are a few other documents out there too.Is there a 
simple tutorial for adding a button to the AXIS screen and having the button 
press generate a message out a serial port?  
 
Thanks
John
 

___
Emc-users mailing list
Emc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-users