Conection with Ambrell

Has anyone connected to an Ambrell with an ignition project?
I’m trying with the serial port but I can’t get the connection

Never heard of it. Links?

Manual.pdf (3.3 MB)

I have this manual, I did some tests with Hyperterminal and if they worked but with ignition I could not make the communication with the serial port

I’d say you would need to add the serial module.

Yes, the serial module will be needed, or an rs485-to-ethernet box, like a Moxa 5k. The protocol is completely custom, so you will need to write a script that cycles through sending the commands you wish and writing responses to tags. Your own “driver”, so to speak. What have you tried so far? (Share your code…)

We have the module. This is a test we run

system.serial.configureSerialPort(\
	port="COM3",\
	bitRate=system.serial.BIT_RATE_38400,\
	dataBits=system.serial.DATA_BITS_8,\
	handshake=system.serial.HANDSHAKE_XON_XOFF,\
	hardwareFlowControl=False,\
	parity=system.serial.PARITY_NONE,\
	stopBits=system.serial.STOP_BITS_1)

And to write a new amperage on the ambrell

#Open port for communication
system.serial.openSerialPort("COM3")
print 'OK'

##Send the command
system.serial.write("COM3",'1,%amps,20')
print 'OK2'

##Close the port
system.serial.closeSerialPort("COM3")
print 'OK3'

The code does not show errors but does not write

Add a carriage return and/or line feed in your written string.

Yes, we already added it but it still does not write.
We also tried this but it only prints the command we send

#Open port for communication
system.serial.openSerialPort("COM3")
print 'OK'

##Send the command
system.serial.write("COM3",'rdata  \r\n')
print 'OK2'

response = system.serial.readBytesAsString("COM3",25)
print response

##Close the port
system.serial.closeSerialPort("COM3")
print 'OK3'

Been a while since I’ve played around with this, but what happens if you use a context manager. (system.serial.port(), in this case)?

Also, the percent sign can be used in string formatting operations. Try putting an r in front of the string to make it a ‘raw’ string.

''' 
    Using the 'with' context manager will wrap all the serial operations in the port manager. 
    No need to use an configureSerialPort / openSerialPort / closeSerialPort
'''
with system.serial.port(\
	port="COM3",\
	bitRate=system.serial.BIT_RATE_38400,\
	dataBits=system.serial.DATA_BITS_8,\
	handshake=system.serial.HANDSHAKE_XON_XOFF,\
	hardwareFlowControl=False,\
	parity=system.serial.PARITY_NONE,\
	stopBits=system.serial.STOP_BITS_1) as port:

	##Send the command
	port.write(r'1,%amps,20') # note the 'r' in front of the string.
	print 'OK2'

Thanks Jordan, I tested the code and it does not mark errors but neither does it write to the device

Are you using HyperTerminal to verify what may be being transmitted?

Yes, commands in HyperTerminal work correctly

Are you hitting the return key in HyperTerminal? If so, you need a \r at the end of the string you write from Ignition.

1 Like

I think you misunderstood. Are you using HyperTerminal on another PC to verify if anything is coming from Ignition?

We found a solution, apparently the code was fine but the Ambrell did not receive the command the first time, what we did was write to it 2 times in a row and that’s how it worked. Thank you @JordanCClark @pturmel