K8056 B-command

I used the same checksum calculation as the S command. However without succes.

The checksum only seems to work if I send Asci characters not with a byte as parameter for the B command.

Basically, to turn on several relays at the same time, replace the ‘S’ by the ‘B’ in your command sequence. As a parameter, a figure between 1 and 255 can be used. 1 = first relay, 2= second relay, 3 = first and second relay etc…
Make sure the checksum is correct.

Of course, the ‘byte’ (figure between 1 and 255) must be sent as ascii, not as a byte. You can post the part of your code that transmits the string, we can take a look at it. I have VB6 experience, and we have some people with VB.net knowledge.

If I would send the B command with value byte 1

Dim checksum, address As Integer
Dim messagestring As String
Dim GPIB As Byte
GPIB = 1
address = 1
If (PositionCountUp.ToString() = MaskedTextBoxGPI1.Text) Then
checksum = (255 - ((((13 + address + Asc(“B”) + GPIB ) / 256) - Int((13 + address + Asc(“B”) + GPIB ) / 256)) * 256)) + 1
messagestring = Chr(13) & Chr(address) & “B” & GPIB & Chr(checksum)
messagestring = messagestring & messagestring
messagestring = messagestring & messagestring
SerialGPI.WriteLine(messagestring)
TimerGPI.Enabled = True
End If

This value is not accepted.

GPIB cannot be declared as a byte. It cannot be added to your messagestring. Try making it an integer and then send it as a chr$

Thanks

I’m facing the same problem.
Unfortunately I’m having a hard time understanding the solution given.
Below you’ll find my code for the transmission over serial interface to K8056.
Everything works perfectly when stetting the relay’s individually (S&C command).
When I want to use the B command, nothing happens.

I’ve tried modifying the code as given the instructions above, but I’ll end up that it isn’t working at all…

Code is used as follows:
Transmit(Ch# to issue, Command (S, C or B))

Code:

[code]
Public Function Transmit(ByVal bteChannel As Byte, ByVal strCommand As String)
'Declare variables
Dim strSendCommand As String = “”
Dim chrChecksum As Char = CalcChecksum(bteChannel, strCommand)
'Compose command string
strSendCommand = Chr(13) & Chr(1) & strCommand & bteChannel & chrChecksum
'Repeat command string for acurate execution
strSendCommand = strSendCommand & strSendCommand
strSendCommand = strSendCommand & strSendCommand
'Send command string to com port
frmMain.prtCOM1.Write(strSendCommand)
End Function

Public Function CalcChecksum(ByVal bteChannel As Byte, ByVal strCommand As String) As Char
    'Declare variables
    Dim bteAddress As Byte = 1
    Dim intChecksum As Integer
    'Calculate 2's complement + 1 for checksum
    intChecksum = (255 - ((((13 + bteAddress + Asc(strCommand) + Asc(bteChannel)) / 256) - Int((13 + bteAddress + Asc(strCommand) + Asc(bteChannel)) / 256)) * 256)) + 1
    'Return the checksum
    Return Chr(intChecksum)
End Function[/code]

What’s wrong?

Hi all,

I also was facing such issue with VB.net.
I wanted to activate relays 1 to 7 at the same time using the “B” command.
There is a problem with VB.net that doesn’t send values up 128 “natively”.

But the solution I found is this:
in my case, the serialportname is SerialPort1.

Here is how I configure it before opening it:

SerialPort1.BaudRate = 2400
SerialPort1.Parity = Parity.None
SerialPort1.DataBits = 8
SerialPort1.StopBits = StopBits.One
SerialPort1.Handshake = Handshake.None
SerialPort1.Encoding = System.Text.Encoding.GetEncoding(28605)

Create the message to send as usualy and write it to the serial port.
Relay 1: item = 1
Relay 2: item = 2
Relay 3: item = 4
… 8…16…32…64…128
Relays 1 and 4: item =5
Relays 3 and 5 and 7: item = (4+16+64) = 84
and so on

I found it here (thank you, all guys on Codeproject.com)
codeproject.com/Questions/23 … l-port-thi

see Solution 1 and Solution 2

I hope this can help many of you facing the same issue with VB.net.

Best regards,
Yvan.