Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BK9050 #116

Closed
ptorrent opened this issue Sep 4, 2023 · 11 comments
Closed

BK9050 #116

ptorrent opened this issue Sep 4, 2023 · 11 comments

Comments

@ptorrent
Copy link

ptorrent commented Sep 4, 2023

Hello,

I'm trying to connect to BK9050.

Without bareClient actived this is what I got during the connecting process:

04-09-2023 15:23:12.862 > error > ads_24 > { ClientException: Connection failed: Device system manager state read failed
04-09-2023 15:23:12.862 > error > ads_24 >     at Socket.socket.once (/node_modules/ads-client/src/ads-client.js:3425:25)
04-09-2023 15:23:12.862 > error > ads_24 >     at <anonymous>
04-09-2023 15:23:12.862 > error > ads_24 >   name: 'ClientException',
04-09-2023 15:23:12.862 > error > ads_24 >   sender: '_connect()',
04-09-2023 15:23:12.862 > error > ads_24 >   adsError: true,
04-09-2023 15:23:12.862 > error > ads_24 >   adsErrorInfo:
04-09-2023 15:23:12.862 > error > ads_24 >    { adsErrorType: 'AMS error',
04-09-2023 15:23:12.862 > error > ads_24 >      adsErrorCode: 8,
04-09-2023 15:23:12.862 > error > ads_24 >      adsErrorStr: 'Unknown command ID' },
04-09-2023 15:23:12.862 > error > ads_24 >   metaData: null,
04-09-2023 15:23:12.862 > error > ads_24 >   errorTrace:
04-09-2023 15:23:12.862 > error > ads_24 >    [ 'readSystemManagerState(): Device system manager state read failed',
04-09-2023 15:23:12.862 > error > ads_24 >      '_sendAdsCommand(): Response with AMS error received' ],
04-09-2023 15:23:12.862 > error > ads_24 >   getInnerException: [Function] }
04-09-2023 15:23:12.921 > error > ads_24 > { ClientException: Connection failed: Device system manager state read failed
04-09-2023 15:23:12.921 > error > ads_24 >     at Socket.socket.once (/node_modules/ads-client/src/ads-client.js:3425:25)
04-09-2023 15:23:12.921 > error > ads_24 >     at <anonymous>
04-09-2023 15:23:12.921 > error > ads_24 >   name: 'ClientException',
04-09-2023 15:23:12.921 > error > ads_24 >   sender: '_connect()',
04-09-2023 15:23:12.921 > error > ads_24 >   adsError: true,
04-09-2023 15:23:12.921 > error > ads_24 >   adsErrorInfo:
04-09-2023 15:23:12.921 > error > ads_24 >    { adsErrorType: 'AMS error',
04-09-2023 15:23:12.921 > error > ads_24 >      adsErrorCode: 8,
04-09-2023 15:23:12.921 > error > ads_24 >      adsErrorStr: 'Unknown command ID' },
04-09-2023 15:23:12.921 > error > ads_24 >   metaData: null,
04-09-2023 15:23:12.921 > error > ads_24 >   errorTrace:
04-09-2023 15:23:12.921 > error > ads_24 >    [ 'readSystemManagerState(): Device system manager state read failed',
04-09-2023 15:23:12.921 > error > ads_24 >      '_sendAdsCommand(): Response with AMS error received' ],
04-09-2023 15:23:12.921 > error > ads_24 >   getInnerException: [Function] }

By setting bareClient to true, it seems able to connect to the device but right after the connection, I got this error:

04-09-2023 15:25:23.175 > error > ads_24 > RangeError: Index out of range
04-09-2023 15:25:23.175 > error > ads_24 >     at checkOffset (buffer.js:977:11)
04-09-2023 15:25:23.175 > error > ads_24 >     at Buffer.readUInt32LE (buffer.js:1039:5)
04-09-2023 15:25:23.175 > error > ads_24 >     at Client._parseAdsData (/node_modules/ads-client/src/ads-client.js:6049:29)
04-09-2023 15:25:23.175 > error > ads_24 >     at Client._parseAmsTcpPacket (/node_modules/ads-client/src/ads-client.js:5875:55)
04-09-2023 15:25:23.175 > error > ads_24 >     at runCallback (timers.js:810:20)
04-09-2023 15:25:23.175 > error > ads_24 >     at tryOnImmediate (timers.js:768:5)
04-09-2023 15:25:23.175 > error > ads_24 >     at processImmediate [as _immediateCallback] (timers.js:745:5)
04-09-2023 15:25:23.208 > error > ads_24 > RangeError: Index out of range
04-09-2023 15:25:23.208 > error > ads_24 >     at checkOffset (buffer.js:977:11)
04-09-2023 15:25:23.208 > error > ads_24 >     at Buffer.readUInt32LE (buffer.js:1039:5)
04-09-2023 15:25:23.208 > error > ads_24 >     at Client._parseAdsData (/node_modules/ads-client/src/ads-client.js:6049:29)
04-09-2023 15:25:23.208 > error > ads_24 >     at Client._parseAmsTcpPacket (/node_modules/ads-client/src/ads-client.js:5875:55)
04-09-2023 15:25:23.208 > error > ads_24 >     at runCallback (timers.js:810:20)
04-09-2023 15:25:23.208 > error > ads_24 >     at tryOnImmediate (timers.js:768:5)
04-09-2023 15:25:23.208 > error > ads_24 >     at processImmediate [as _immediateCallback] (timers.js:745:5)

This is happending when I try to read this register: group:16416 offset:2 length:1

Do you know why I get this error ?

Thanks for your help !

@ptorrent
Copy link
Author

ptorrent commented Sep 4, 2023

For your information, I'm using an export of symbols:

<PlcProjectInfo>
	<RoutingInfo>
		<AdsInfo>
			<NetId>192.168.1.232.1.1</NetId>
			<Port>100</Port>
		</AdsInfo>
	</RoutingInfo>
	<Symbols>
		<Symbol>
			<Name>KL6781-0000_1_Channel_1.State</Name>
			<Type>UINT</Type>
			<IGroup>61472</IGroup>
			<IOffset>0</IOffset>
			<BitSize>16</BitSize>
		</Symbol>
...

I'm trying to subscribe to the symbole name and I got this error "Index out of range".

So I tried to get raw value with groupIndex and offset but same error !

The result of a read is: (buffer is the value, USINT is the datatype from export )

04-09-2023 20:15:58.997 > error > ads_24 > <Buffer 00> USINT
04-09-2023 20:15:58.997 > error > ads_24 > <Buffer 00> USINT
04-09-2023 20:15:59.009 > error > ads_24 > <Buffer 00> USINT
04-09-2023 20:15:59.009 > error > ads_24 > <Buffer 00> USINT

	client.readRaw(61472,0,2).then(function(res){
					console.error(res,'UINT')
					client.convertFromRaw(res, 'UINT').then(function(value){
						
					}).catch(function(err){
						
					})
				}).catch(function(err){

				})

The issue seems coming from "convertFromRaw"

@jisotalo
Copy link
Owner

jisotalo commented Sep 4, 2023

Could you please show the Node.js code you are using with connection settings?

Quickly looking the port could be also 300 (https://download.beckhoff.com/download/document/io/bus-terminals/bk9000_bk9050_bk9100en.pdf):
image

Edit: And yes most probably these BK systems have no system manager so bareClient is the correct/only option.

@ptorrent
Copy link
Author

ptorrent commented Sep 5, 2023

Thanks for your answer, this is my settings:

 var settings = { 
	localAmsNetId: '192.168.1.110.1.1',
	localAdsPort: 32905,
	targetAmsNetId: '192.168.1.232.1.1',
	targetAdsPort: 300,
	allowHalfOpen: true,
	bareClient: true,
	readAndCacheSymbols: false,
	routerAddress: '192.168.1.232',
	routerTcpPort: 48898 
}
client = new ads.Client(settings)
client.connect().then(function(err){
		client.subscribe("KL6781-0000_1_Channel_1.State", (data, sub) => {
			console.error('change')
		}, cycleTime).then(function(sub){
			console.error('success!')
		}).catch(function(err){
		        console.error('failed !',err)
		})
})

I don't receive Change / success! / failed! log. Just:

05-09-2023 05:54:09.097 > error > ads_24 > RangeError: Index out of range
05-09-2023 05:54:09.097 > error > ads_24 >     at checkOffset (buffer.js:977:11)
05-09-2023 05:54:09.097 > error > ads_24 >     at Buffer.readUInt32LE (buffer.js:1039:5)
05-09-2023 05:54:09.097 > error > ads_24 >     at Client._parseAdsData (/node_modules/ads-client/src/ads-client.js:6049:29)
05-09-2023 05:54:09.097 > error > ads_24 >     at Client._parseAmsTcpPacket (/node_modules/ads-client/src/ads-client.js:5875:55)
05-09-2023 05:54:09.097 > error > ads_24 >     at runCallback (timers.js:810:20)
05-09-2023 05:54:09.097 > error > ads_24 >     at tryOnImmediate (timers.js:768:5)
05-09-2023 05:54:09.097 > error > ads_24 >     at processImmediate [as _immediateCallback] (timers.js:745:5)

I am able to read the value but not decode it. Seems that i'm also able to subscribe to the symbol name, but still same error. However, I feel like I'm only receiving 00 Buffer or 00 00 depending the length.

@jisotalo
Copy link
Owner

jisotalo commented Sep 6, 2023

What happens when you try to read it using indexGroup and indexOffset with readRaw()?

I'm not too familiar with BK9050 and I don't have any unit to test myself.

@ptorrent
Copy link
Author

ptorrent commented Sep 6, 2023

I'm able to get the value: Buffer(00 00)

client.connect().then(function(err){
                             client.readRaw( target.group,target.offset,target.length).then(function(res){
					===> OK I've the res

					===> crash the process on convertion
					client.convertFromRaw(res, target.type).then(function(value){
						
					})
				}).catch(function(err){
				
				})
})

@jisotalo
Copy link
Owner

jisotalo commented Sep 6, 2023

Is the value correct? Can you get a value that isn't 0?

@ptorrent
Copy link
Author

ptorrent commented Sep 6, 2023

I will check it tonight and let you know, not at my desk, thanks for your support

@ptorrent
Copy link
Author

ptorrent commented Sep 8, 2023

Hello again, I was able to decode value by adding this in ads-client.js line 6049:

try{
  switch (packet.ams.adsCommand) {
....
  debugD(`_parseAdsData(): ADS data parsed: %o`, ads)
} catch(e){}

values are correct

@ptorrent
Copy link
Author

ptorrent commented Sep 8, 2023

But with that solutation, cannot read value with readSymbol because of this error and readRaw for BOOL type:

I think that catching the decode error remove some properties needed for decoding value

ClientException: Reading data failed (Cannot read property 'byteLength' of undefined)
line 1442

Others types working fine, UINT etc...

If you want to check a bit, I can give you access to the linux machine. We can pay for your support as well

@jisotalo
Copy link
Owner

@ptorrent can you send me email. You can find the address from package.json details for example.

jisotalo added a commit that referenced this issue Sep 23, 2023
…ength if answering with error code

  - This caused `RangeError: Index out of range` exception as there wasn't enough bytes received
  - See [issue #116](#116)
- Bug fix: If using older Node.js versions such as 8.x, connection lost could have caused unhandled exception
  - Reason was `catch {}` which isn't supported in old versions
  - See [issue #116](#116)

- Updated readme to include information about TypeScript types
  - Thanks to [Christian Rishøj](https://github.com/crishoj)
- Updated readme with FAQ about TwinCAT 2 low-end devices
- Updated readme about v2 development
- Added option to run tests with usermode runtime AmsNetId (`192.168.4.1.1.1`) instead of localhost (`npm run test-um`)
jisotalo added a commit that referenced this issue Sep 23, 2023
## [1.14.3] - 23.09.2023
### Changed
- Bug fix: Some TwinCAT 2 devices (such as BK9050) do not send data length if answering with error code
  - This caused `RangeError: Index out of range` exception as there wasn't enough bytes received
  - See [issue #116](#116)
- Bug fix: If using older Node.js versions such as 8.x, connection lost could have caused unhandled exception
  - Reason was `catch {}` which isn't supported in old versions
  - See [issue #116](#116)

### Added
- Updated readme to include information about TypeScript types
  - Thanks to [Christian Rishøj](https://github.com/crishoj)
- Updated readme with FAQ about TwinCAT 2 low-end devices
- Updated readme about v2 development
- Added option to run tests with usermode runtime AmsNetId (`192.168.4.1.1.1`) instead of localhost (`npm run test-um`)
@jisotalo
Copy link
Owner

Issues related to this are now fixed in 1.14.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants