Visual basic and cfa-633

But is data(1) always the same, and data(2) always the same? It doesn't matter if the crc is the same, it matters if it is correct. Whenever the temperature changes, the crc will change also. If your data is corrupt, you won't know it unless you calculate the crc on the first 6 bytes (type, length, data) and compare to the crc bytes.
Looking for additional LCD resources? Check out our LCD blog for the latest developments in LCD technology.
 
USB LCD Displays - Graphic and Character LCDs with a Keypad

ejf28

New member
I think the crc isn't good. Here is the code i used, i even tried checking the hi and lo to see if they were reversed but they are different.

Code:
Dim Type As Byte
        Dim Length As Byte
        Dim Packet As String
        Dim data(256) As Byte

        Type = sp.ReadByte()    'get packet type
        Length = sp.ReadByte()    'get data length
        Packet = "Type: " & Type & " Length: " & Length & " "

        Dim i As Integer
        If Length <> 0 Then        'if any data in the packet

            For i = 0 To Length - 1    'read the data bytes

                data(i) = sp.ReadByte

            Next i
            Packet = Packet & " "
        End If
        Dim crclo As String
        Dim crchi As String
        crclo = sp.ReadByte()
        crchi = sp.ReadByte()


        Packet = Packet & "Crc: " & crclo    'the first crc byte
        Packet = Packet & "," & crchi '2nd crc byte



        If tempsensor = True Then
            'data has data
            'data(0) = temp sensor number
            'data(1) = msb of temp sensor
            'data(2) = lsb of temp sensor
            'data(3) = dow crc status



            'check if crc is good
            Dim test(256) As Byte
            Dim crc As WORD
            Dim match As String = ""
            test(0) = Type
            test(1) = Length
            test(2) = data(0)
            test(3) = data(1)
            test(4) = data(2)
            test(5) = data(3)

            crc = Get_Crc(data, 6)
            If crc.Lo = crclo Then
                If crc.Hi = crchi Then
                    match = "Good Crc"
                End If
            End If




            Dim Tcounts As Integer
            Dim msb As Integer
            Dim lsb As Integer
            Dim debug As String

            msb = Convert.ToInt32(data(1))
            lsb = Convert.ToInt32(data(2))
            lsb = lsb And &HFF




            debug = "Data: " & data(1) & " " & data(2) & " msb: " & msb & " lsb: " & lsb
            Tcounts = msb * 256
            debug = debug & " Tc_Hi: " & Tcounts
            Tcounts = Tcounts + lsb
            debug = debug & " Tc: " & Tcounts

            'Degc = Convert.ToDouble(Tcounts) / 16.0
            textforrtb = debug
 
I think the crc isn't good. Here is the code i used,
I would change these two items, as type "String" is not appropriate:
Code:
        Dim crclo As Byte
        Dim crchi As Byte
Otherwise your code looks OK. You could use the command 1 to read the hw/fw version, as a constant reply with a known crc, to check your code.
C=65( 1 = Read Version),L=16,D="CFA633:h1.5,k1.9",CRC=0xD058, where &H58 is crclo, and &HD0 is crchi.

BTW, I now have a CFA633-TMC-KS to test with, thanx to CFA Tech Support.
 

ejf28

New member
Oops I actually wrote it wrong

Code:
'check if crc is good
            Dim test(256) As Byte
            Dim crc As WORD
            Dim match As String = ""
            test(0) = Type
            test(1) = Length
            test(2) = data(0)
            test(3) = data(1)
            test(4) = data(2)
            test(5) = data(3)

            crc = Get_Crc(test, 6)
            If crc.Lo = crclo Then
                If crc.Hi = crchi Then
                    match = "Good Crc"
                End If
            End If
Before I had crc = Get_Crc(data, 6), it should be crc = Get_Crc(test, 6) as it is now. Once that was fixed the crc values are always correct
 
What about data(1) and data(2)? Are they believable values? On my 633, with the probes at about 20°C, the temp data bytes are msb = &h01, lsb = &h4A.
 

ejf28

New member
my data(1) value ranges from 2 to 4 or so and my data(2) is usually 2 or close, dunno what they are in the format you wrote them as
 
So, you don't understand the hex format (&H00-&HFF, or in C syntax 0x00-0xFF)? Not too important.

my data(1) value ranges from 2 to 4 or so and my data(2) is usually 2 or close
This is bizarre. If data(1), the msb, ranges from 2 to 4, that means your temperatures are:

(2 * 256) / 16 = 32°C
(4 * 256) / 16 = 64°C

Data(2) should vary from 0-255, and when it rolls over/under, then data(1) will change by 1 count. If data(2) is "usually 2 or close" then data(1) could not possibly vary from 2 to 4.

So, in my opinion, your temperature values are NOT believable, even if the packet crc is good.
 

ejf28

New member
would they seem off due to the way that i outputted them? i just said that the output text is equal to data(1) & data(2). do i need to do any conversions? also before i tried to output the results as an integer and even thouh they seemed off from actual values, they went up and down when i ajusted my fan speeds meaning there seems to be a coorelation of some kind at least.
 
I don't know why your code is not producing correct temperature values, and I don't know if the conversions are at fault. I did a bit of searching to find out how to impliment a union in VB. I don't know if this will work, but give it a try. I can't post the code directly because the forum software mangles the parts with the ">" and "<". If this doesn't help, then I think I am through.

<structlayout(layoutkind.explicit)><fieldoffset(0)><fieldoffset(0)><structlayout(layoutkind.explicit)><structlayout(layoutkind.explicit)\><fieldoffset(0)\><fieldoffset(0)\><fieldoffset(0)><fieldoffset(0)></fieldoffset(0)></fieldoffset(0)></fieldoffset(0)\></fieldoffset(0)\></structlayout(layoutkind.explicit)\></structlayout(layoutkind.explicit)></fieldoffset(0)></fieldoffset(0)></structlayout(layoutkind.explicit)>
 

Attachments

ejf28

New member
Where did you get the example from? Alot of errors when trying to put it into vb .net, guessing it was from vb 6.0. It might be a good start at least. Btw doesn't know if it helps any but if i output the msb and lsb as an int32 they become around 90 and 3
 
Last edited:

ejf28

New member
I didn't really understand the relation between a decimal value and the msb and lsb values but after doing some research I found this site that shows how to calculate msb and lsb values from a decimal, so obviously the opposite to go from msb and lsb to decimal.
http://www.decisioncards.com/io/tutorials/8254_tut2.html
I am sure you already know all this but I figured that I'd post any new information I found.

To calculate the msb and lsb values (made a mini program using textbox1 as the decimal, textbox2 as the msb, and textbox3 as the lsb:
Code:
            Dim dec As Decimal
            Dim msb As Integer
            Dim value1 As Decimal
            Dim value2 As Decimal
            Dim lsb As Integer

            dec = TextBox1.Text
            value1 = dec / 256
            msb = value1
            value2 = value1 - msb
            lsb = value2 * 256

            TextBox2.Text = msb
            TextBox3.Text = lsb
and in reverse to find the decimal:

Code:
            Dim msb As Integer
            Dim lsb As Integer
            Dim value As Decimal
            Dim value1 As Decimal
            Dim dec As Decimal

            msb = TextBox2.Text
            lsb = TextBox3.Text
            value = lsb / 256
            value1 = value + msb
            dec = value1 * 256
            TextBox1.Text = dec
Now I guess it makes sense why the msb fluctuating even by 1 has such a big change on the decimal value. This probably isn't any real breakthrough and stuff you already know but at least I learned something myself haha. Now I have to look into those values given by the lcd more thoroughly since I understand it better.
 
I wonder if your temperature values are being byte swapped at some point. I don't know if VB uses Big Endian or Little Endian, but maybe we're assuming the wrong one. If you are not familiar with the term Endian, look it up in Wikipedia.

What happens if you swap msb and lsb?
 

ejf28

New member
Amazing I switched them and used the same method as listed earlier and appears to be reasonable numbers. Not sure of what a good test is for ensuring accuracy but the temps range from 30 to 37 degrees when messing with the fan speeds which would be normal temps.
 
Top