# readBytesAsString Error

**URL:** <https://forum.inductiveautomation.com/t/readbytesasstring-error/41788>\
**Category:** Ignition\
**Tags:** ignition79\
**Created:** [December 25, 2020, 10:18am UTC](https://forum.inductiveautomation.com/t/readbytesasstring-error/41788 "2020-12-25T10:18:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![stefan.wang](https://avatars.discourse-cdn.com/v4/letter/s/b19c9b/32.png) [@stefan.wang](https://forum.inductiveautomation.com/u/stefan.wang)\
**Post date:** [December 25, 2020, 10:18am UTC](https://forum.inductiveautomation.com/t/readbytesasstring-error/41788/1 "2020-12-25T10:18:17Z")

</div>

Hi there  
Good day

i run system.serial.readBytesAsString() and find that the return value is sometimes incomplete  
for example:  
The string Scaned： test123456789

sometime the string returned in value：  
test12345 or test or test123456  
There are no rules

```auto
def readData(rootContainer=event.source.parent):
	Port=rootContainer.ScanCom1
	print 'present COM',Port
	recv=''
	errMsg=''
	try:
		system.serial.configureSerialPort(\
		port=Port,\
		bitRate=system.serial.BIT_RATE_115200,\
		dataBits=system.serial.DATA_BITS_8,\
		handshake=system.serial.HANDSHAKE_NONE,\
		hardwareFlowControl=False,\
		parity=system.serial.PARITY_NONE,\
		stopBits=system.serial.STOP_BITS_1)
		
		system.serial.openSerialPort(Port)
# www=system.serial.readBytes(Port,10)
# print 'byte',www
		recv=system.serial.readBytesAsString(Port,50,10000)
		
# recv=system.serial.readLine(Port,10000)
		print recv+'wwwwww'
		if recv:
			print recv,len(recv)
		else:
			errMsg=u'接收空数据'
		system.serial.closeSerialPort(Port)
	except :
		errMsg=u'打开串口失败或通讯超时'
		system.serial.closeSerialPort(Port)
	def sendBack(recv=recv,errMsg=errMsg,rootContainer=rootContainer):
		import system	
		if recv:
			rootContainer.getComponent('txtscan 1').ScanData=recv
		print 'newerr--------------->',errMsg
		rootContainer.getComponent('lberr 1').text=errMsg
		if errMsg=='':
			event.source.doClick()
	system.util.invokeLater(sendBack)

system.util.invokeAsynchronous(readData)

* List item

```
