0

I am intending to display today's date and time on Silicon Craft 2004 ModBus (SC2004MBS). I tried to left shift the value date string and pass to the device using write_registers() function. The code looks like this:

@defer.inlineCallbacks
def DtTm():
  dt = datetime.datetime.now()
  dd= dt.strftime('%d/%m/%Y')
  da = [ord(c) for c in dd]
  display = yield protocol.write_registers(10, da, unit=1)

The code block is called using Twisted callbacks. The output do show the result on the device but with some unwanted characters before each characters on the display screen.enter image description here

kushvarma
  • 369
  • 2
  • 6

1 Answers1

1

The ord() function generated Unicode encoding, the SC2004MBS is an ASCII display. The unwanted characters are presumably the glyph associates with zero.

The display takes two ASCII characters per register write, but the byte order appears to differ from that of your generating system since the NUL appears after the wanted character. So you probably need to byte swap the character pairs in dd and then print that as 5 register values.

Clifford
  • 88,407
  • 13
  • 85
  • 165
  • @CIifford, I did try to byteswap using the following code, `da = np.array([(ord(c))for c in dd], dtype=np.int16) da.byteswap(True)` but not able to get the desired output. I used numpy library. – kushvarma Oct 22 '17 at 15:56
  • But you are still generating Unicode characters! I am not A Python expert, I have no idea whether your byteswap code is correct, but using Unicode is incorrect. – Clifford Oct 22 '17 at 16:28
  • I suggest that you start with `display = yield protocol.write_registers(5, dd, unit=1)`, we if you then get the correct characters and length, then worry about the byte order if, as I suspect they will be, they are pair-swapped. – Clifford Oct 22 '17 at 16:35