Welcome, Guest

TOPIC: execute commands via RS232 while running program?

execute commands via RS232 while running program? 11 months 1 week ago #2345

  • hzw
  • hzw's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 3
  • Karma: 0
I don't know if the below is possible.

I am currently sending commands to a motor (SM23165D RS232) from a PC. No program is present/running on the motor.
The setup has now been expanded to include 2 safety switches connected to the GPI/O 1 en 2 of the motor. If the switches are open, the inputs are high and all received commands should be executed. If 1 or both of the switches are closed the motor should stop immediately until both switches are open again. I could implement this either by:
  • continuously reading the motor pins from the PC (while also executing commands) and stopping if either is low
  • having a program run on the smartmotor that continuously watches the pins but also executes commands from the PC

The problem with the 1st method is that I would need to poll the motor continuously (and fast) which I think would slow down the command execution. The 2nd method seems better and faster.

Is method 2 possible? Simultaneously executing a smartmotor program which guards inputs on the motor while also executing commands received from the PC? And if so, is there example code for this?
The administrator has disabled public write access.

execute commands via RS232 while running program? 11 months 1 week ago #2346

  • mmeyer
  • mmeyer's Avatar
  • OFFLINE
  • Moderator
  • Posts: 39
  • Thank you received: 11
  • Karma: 3
Hello,

There is a quite simple way to do this. All you need is to load a program to the SmartMotor that runs an interrupt triggered by either of the switches being activated, and doesn't accept commands until that state changes. This would still allow you to send commands as you had been. Your program could be:
ITR(0, 16, 1 , 0, 1) 'setup interrupt for when I/O 1 goes low
ITR(1, 16, 2, 0, 1)     'interrupt for I/O 2
EITR(0)
EITR(1)
ITRE

PAUSE       'allows interrupts to keep working
END

C1                         'interrupt subroutine
CCHN(RS2,0)                   'close the RS-232 channel
WHILE B(16,1)==0|B(16,2)==0 LOOP    'wait for switches to open again
OCHN(RS2,00, N, 9600, 1, 8, C)	        'reopen channel 
RETURNI

For more information on the commands & syntax, see the developer's guide.
Last Edit: 11 months 1 week ago by mmeyer.
The administrator has disabled public write access.
The following user(s) said Thank You: hzw

execute commands via RS232 while running program? 10 months 3 weeks ago #2356

  • hzw
  • hzw's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 3
  • Karma: 0
Hi mmeyer,

thanks for confirming that interrupt + command should be possible.
I have modified your example somewhat (only using 1 input, high to stop and I prefer not to stop communication):
EIGN(0)                   'make sure input 0 is configured as input
ITR(0, 16,  0, 1, 1)   'configure interrupt 0 using word 16, bit 0 on 0-to-1 change
EITR(0)                    'enable interrupt 0
ITRE                        'enable all interrupts

PAUSE                    'this is where RETURNI returns to
END

C1
ITRD                       'disable all other interrupts
WHILE B(16,0)==1 'as long as word 16, bit 0 is high do what is before loop
S                             'emergency stop
LOOP
ITRE                       're-enable interrupts
RETURNI               ' return from interrupt

When I try this in the SmartMotor Playground it behaves as I expect. When I keep the key pressed I can move the motor, and when I release the button the motor stops.

But when I use the (own developed) software on my PC to control the motor, it ignores that switch completely. It is as if the remote commands bypass/prevent the program in the motor from running.

Does anyone have an idea why that could be?
The administrator has disabled public write access.

execute commands via RS232 while running program? 10 months 3 weeks ago #2357

  • mmeyer
  • mmeyer's Avatar
  • OFFLINE
  • Moderator
  • Posts: 39
  • Thank you received: 11
  • Karma: 3
Are you using SMIengine for your program? Addressing the motors would issue an END, thereby stopping the interrupt action.
Last Edit: 10 months 3 weeks ago by mmeyer.
The administrator has disabled public write access.
The following user(s) said Thank You: hzw

execute commands via RS232 while running program? 9 months 3 weeks ago #2387

  • hzw
  • hzw's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 3
  • Karma: 0
Thank you for this response!

I'm sorry for my late reply. I am using the SMIEngine for my program. In a C# program I call the COM functions.
I did not know that addressing the motors would issue an END. Is there more information available on this? The SMIEngine Help file did not mention this. Is there a way to prevent the SMIEngine from issuing and END command? Or should I try to restart the program on the motor after establishing the connection?

(I also suspected the interrupt setting. With the current version of the program I will detect a low-to-high transition and stop the motor, but what if the input is already high when the motor is powered up? That is no low-to-high transition, and would not execute the interrupt routine.
The administrator has disabled public write access.

execute commands via RS232 while running program? 9 months 3 weeks ago #2388

  • mmeyer
  • mmeyer's Avatar
  • OFFLINE
  • Moderator
  • Posts: 39
  • Thank you received: 11
  • Karma: 3
Hello,

The proper thing to do after addressing your motor(s) would be to issue a "RUN" command- if running the downloaded program is what you want.

You are correct in that an interrupt will only be triggered on a transition, and if an input starts in the state of interest with no transition, the interrupt will not be called. There are other ways to reach your desired effect, depending on what that effect is and how fast you want it to happen.
The administrator has disabled public write access.
The following user(s) said Thank You: hzw
Time to create page: 0.179 seconds
Powered by Kunena Forum