web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Reading data from an electronic scale into form

(0) ShareShare
ReportReport
Posted on by

Hello All

I need to read an electronic scale into Dynamics AX 2012 R3 CU11. The situation is as follows:

You have lorries which are weigh on a scale and the reading should be displayed in a field in a form.

How should I go about and is it possible to do that in AX.?

Will much appreciate any help.

Thanks 

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Community Member Profile Picture
    on at
    RE: Reading data from an electronic scale into form

    Hello Vilmos

    Thank you very much for your help and guidance.

    Thank you also Martin.

  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at
    RE: Reading data from an electronic scale into form

    It seems to be some sort of serial port communication, so you could utilize the .Net namespace of SerialPorts in AX:

    msdn.microsoft.com/.../system.io.ports.serialport(v=vs.110).aspx

    We can provide general guidance on the community to point you in a direction which can lead to the correct result, but you need to do the actual implementation yourself. If it is above your skills, it is better to contract it out to someone who has the proper knowledge to go on with this.

  • Community Member Profile Picture
    on at
    RE: Reading data from an electronic scale into form

    Hello Vilmos

    I will be doing it but I am a beginner in AX 2012.

    Is it possible that you explain to me how I can implement it in AX.

    Thanks

  • Vilmos Kintera Profile Picture
    46,149 on at
    RE: Reading data from an electronic scale into form

    Great, if you have the VB-script, all you need to do is to get your developer to implement it!

  • Community Member Profile Picture
    on at
    RE: Reading data from an electronic scale into form

    Hello Martin

    This is the code doing the capture.

    Public Function GetWeight() As Double

           Dim TheWeight As Double

           ' See which protocol this weight bridge uses, reads the data, then

           ' return it.

           ' We are just hard coding this right now, a cleaner implementations is required

           Try

               TheWeight = CDbl(Mid(GetRawData(CommandType.cmdAscii, False, "5"), 4, 5))

               'TheWeight = CDbl(Mid("x 09010kg", 3, 5))

           Catch ex As Exception

               TheWeight = 0

               MsgBox("Error reading scale, try getting reading again. If error persists contact administrator")

           End Try

           Return TheWeight

       End Function

    ''' This method basically sends a command to the weightbridge, then waits

       ''' for the reply back. We assume that validation has already

       ''' been done that if the command type is ASCII, then the proper

       ''' values has been sent. This is used to get raw data. While reading

       ''' and sending the data, it may time out because the weightbridge is not

       ''' ready, as such we have to check the time outs and retry.

       ''' </summary>

       ''' <param name="aCommandType">The type on which the command is, its either

       ''' an ascii character or a string character</param>

       ''' ''' <param name="aCommandText">The command to send to the weightbridge</param>

       ''' <param name="anIncludeCRLF">Whethter a neew line character should be added at the end of the command.</param>

       ''' <returns>the bytes converted as string returned by the weightbridge</returns>

       ''' <remarks></remarks>

       Public Function GetRawData(ByVal aCommandType As clsWeightBridgeManager.CommandType, ByVal anIncludeCRLF As Boolean, _

       ByVal aCommandText As String) As String

           Dim MyCommandText As String

           Dim MySerialData As String

           Dim MyNumTrial As Integer

           ' We build the command to send

           ' If my command type is ascii, then we are receiving the command as a string

           ' representing an ascii char between 0 and 255

           If (aCommandType = CommandType.cmdAscii) Then

               MyCommandText = Chr(CInt(aCommandText))

           Else

               MyCommandText = aCommandText

           End If

           ' Now we verify if we have to add a carriage return

           If (anIncludeCRLF) Then

               MyCommandText = MyCommandText & Microsoft.VisualBasic.vbCrLf

           End If

           ' We ensure that the data received is empty

           MySerialData = ""

           ' We open the port and try sending the command to the weightbridge

           Try

               TheSerialPort.Open()

               TheSerialPort.DiscardOutBuffer()

               TheSerialPort.DiscardInBuffer()

               TheSerialPort.Write(MyCommandText)

           Catch e As Exception

               ' soem stupd thing happened

               MsgBox("Could not open port")

           End Try

           MyNumTrial = 4

           MySerialData = TheSerialPort.ReadExisting

           TheSerialPort.DiscardInBuffer()

           ' it could have been that we did not get any data yet, so we

           ' try a couple more times

           While ((MyNumTrial > 0) Or (MySerialData = ""))

               ' we try the reading 4 times as .25 second interval to get the data

               Thread.Sleep(250)

               ' we read again

               MySerialData = MySerialData & TheSerialPort.ReadExisting

               TheSerialPort.DiscardInBuffer()

               MyNumTrial = MyNumTrial - 1

           End While

           ' We flush the buffers and close

           TheSerialPort.DiscardInBuffer()

           TheSerialPort.DiscardOutBuffer()

           TheSerialPort.Close()

           Return MySerialData

       End Function

  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at
    RE: Reading data from an electronic scale into form

    We are also about to implement weight and dimension measurement of goods in our warehouse. I am afraid you need to specifically choose a scale that supports some kind of API, with which you could pull information from.

    It could be anything from a web service, COM application calls, DLL which allows access to the scale driver, or file based output - does not matter which one is available as long as the scale can produce anything useful that AX could consume.

    As Martin said, you need to consult with the scale's vendor to see how can you pull the measurement information in the above mentioned ways, without using that VB application.

    Worst case scenario if they do not have anything is to try to decompile the VB application with a skilled .Net developer, and see how does it use the driver, and try to replicate those yourself directly from AX possibly through a Visual Studio project and .Net references.

  • Community Member Profile Picture
    on at
    RE: Reading data from an electronic scale into form

    Ok I will check and revert.

    Thanks

  • Martin Dráb Profile Picture
    235,979 Most Valuable Professional on at
    RE: Reading data from an electronic scale into form

    Yes, I understand from the very beginning that you want do it from AX. That's exactly why you need to find out what API the scales offer. You can't write code in AX if you don't know how to communicate with the hardware.

  • Community Member Profile Picture
    on at
    RE: Reading data from an electronic scale into form

    Ok I will check. But the thing is that, the company wants to phase out the VB interface and do everything in AX 2012. That is, the user will do same in AX.

  • Martin Dráb Profile Picture
    235,979 Most Valuable Professional on at
    RE: Reading data from an electronic scale into form

    You have to look at the programming interface (not the GUI) that the application uses to communicate with the scale.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Syed Haris Shah Profile Picture

Syed Haris Shah 9

#2
Community Member Profile Picture

Community Member 2

#2
Mea_ Profile Picture

Mea_ 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans