Wert von mb2hal konvertieren

More
30 May 2024 18:23 #301874 by Kittifix
Ich bekomme von mb2hal einen Stromwert geliefert :  bei Fahrt in positiver Richtung :  5 ,bei Fahrt in negativer Richtung:  65531

in Halshow steht : Type s32out ???

wie bekomme ich einen normalen Wert ?

(bei Drehmoment,Geschwindigkeit ,Last usw ist es genauso )

Grüße
Kittifix
 

Please Log in or Create an account to join the conversation.

More
15 Jun 2024 08:39 #303034 by andypugh
It looks like modbus doesn't actually have the concept of negative numbers, (based on a quick web search)

If you are using a Mesa card then you could consider using mesa_modbus as that automatically re-wraps the 16 bit value into a signed value (github.com/LinuxCNC/linuxcnc/blob/master...a_modbus.c.tmpl#L773 )

Looking through the mb2hal code I don't see anything with looks to do this wrap (but it is possible that I missed it)

It's not an elegant solution, but a custom HAL component could be written to do the conversion.

linuxcnc.org/docs/stable/html/hal/comp.html
component s16 "convert s32 modbus 16 but int into signed";
pin in signed in;
pin out signed out;
function _;
license "GPL"; // indicates GPL v2 or later
;;
if (in > 32768) {
   out = in - 63336;
} else {
  out = in;
}

Please Log in or Create an account to join the conversation.

More
25 Jun 2024 21:09 #303789 by HansU
Replied by HansU on topic Wert von mb2hal konvertieren
(Ich hoffe englisch ist okay für dich)
I guess the problem here is that the modbus data are usually 16 bit wide and so does mb2hal interprets them.
But as the Linuxcnc HAL don't have have s16 and u16 types, the types in the C-code are chosen to match the HAL types so s32 is used for integer, so it will never wrap.
A possible fix for mb2hal would be to use s16 and u16 internally and then cast them to s32 and u32. But then we need a new for pin for each function code...

But until this happens ... I don't really see a better way than using a custom component like Andy suggested.

Please Log in or Create an account to join the conversation.

Time to create page: 0.169 seconds
Powered by Kunena Forum