コード例 #1
0
def initaliseSMAConnection(btSocket, mylocalBTAddress, MySerialNumber,
                           packet_send_counter):
    # Wait for 1st message from inverter to arrive (should be an 0002 command)
    bluetoothbuffer = read_SMA_BT_Packet(btSocket, mylocalBTAddress)
    checkPacketReply(bluetoothbuffer, 0x0002)

    netid = bluetoothbuffer.levelone.getByte(4)
    #print "netid=%02x" % netid
    inverterAddress = bluetoothbuffer.levelone.SourceAddress

    # Reply to 0x0002 cmd with our data
    send = SMABluetoothPacket(0x1F, 0x00, 0x00, 0x02, 0x00, mylocalBTAddress,
                              inverterAddress)
    send.pushUnescapedByteArray(
        bytearray([
            0x00, 0x04, 0x70, 0x00, netid, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
            0x00, 0x00
        ]))
    send.finish()
    send.sendPacket(btSocket)

    # Receive 0x000a cmd
    bluetoothbuffer = read_SMA_BT_Packet(btSocket, mylocalBTAddress)
    checkPacketReply(bluetoothbuffer, 0x000a)

    # Receive 0x000c cmd (sometimes this doesnt turn up!)
    bluetoothbuffer = read_SMA_BT_Packet(btSocket, mylocalBTAddress)
    if bluetoothbuffer.levelone.CommandCode(
    ) != 0x0005 and bluetoothbuffer.levelone.CommandCode() != 0x000c:
        raise Exception("Expected different command 0x0005 or 0x000c")

    # Receive 0x0005 if we didnt get it above
    if bluetoothbuffer.levelone.CommandCode() != 0x0005:
        bluetoothbuffer = read_SMA_BT_Packet(btSocket, mylocalBTAddress)
        checkPacketReply(bluetoothbuffer, 0x0005)

    # Now the fun begins...

    send = SMABluetoothPacket(0x3f, 0x00, 0x00, 0x01, 0x00, mylocalBTAddress)
    pluspacket1 = SMANET2PlusPacket(0x09, 0xa0, packet_send_counter,
                                    MySerialNumber, 0, 0, 0)
    pluspacket1.pushLong(0x00000200)
    pluspacket1.pushLong(0x00000000)
    pluspacket1.pushLong(0x00000000)
    send.pushRawByteArray(pluspacket1.getBytesForSending())
    send.finish()
    send.sendPacket(btSocket)

    bluetoothbuffer = read_SMA_BT_Packet(btSocket, packet_send_counter, True,
                                         mylocalBTAddress)
    checkPacketReply(bluetoothbuffer, 0x0001)
    if bluetoothbuffer.leveltwo.errorCode() > 0:
        raise Exception("Error code returned from inverter")

    packet_send_counter += 1
コード例 #2
0
def initaliseSMAConnection(btSocket, mylocalBTAddress, AddressFFFFFFFF,
                           InverterCodeArray, packet_send_counter):
    # Wait for 1st message from inverter to arrive (should be an 0002 command)
    bluetoothbuffer = read_SMA_BT_Packet(btSocket, mylocalBTAddress)
    checkPacketReply(bluetoothbuffer, 0x0002)

    netid = bluetoothbuffer.levelone.getByte(4)
    #print "netid=%02x" % netid
    inverterAddress = bluetoothbuffer.levelone.SourceAddress

    # LogMessageWithByteArray("inverterAddress", inverterAddress)

    # Reply to 0x0002 cmd with our data
    send = SMABluetoothPacket(0x1f, 0x00, 0x00, 0x02, 0x00, mylocalBTAddress,
                              inverterAddress)
    send.pushUnescapedByteArray(
        bytearray([
            0x00, 0x04, 0x70, 0x00, netid, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
            0x00, 0x00
        ]))
    send.finish()
    # print send.DisplayPacketDebugInfo("Reply to 0x02 cmd")
    send.sendPacket(btSocket)
    #pause()

    # Receive 0x000a cmd
    bluetoothbuffer = read_SMA_BT_Packet(btSocket, mylocalBTAddress)
    checkPacketReply(bluetoothbuffer, 0x000a)

    # Receive 0x000c cmd (sometimes this doesnt turn up!)
    bluetoothbuffer = read_SMA_BT_Packet(btSocket, mylocalBTAddress)
    if bluetoothbuffer.levelone.CommandCode(
    ) != 0x0005 and bluetoothbuffer.levelone.CommandCode() != 0x000c:
        print("Expected different command 0x0005 or 0x000c")

    # Receive 0x0005 if we didnt get it above
    if bluetoothbuffer.levelone.CommandCode() != 0x0005:
        bluetoothbuffer = read_SMA_BT_Packet(btSocket, mylocalBTAddress)
        checkPacketReply(bluetoothbuffer, 0x0005)

    # Now the fun begins...

    send = SMABluetoothPacket(0x3f, 0x00, 0x00, 0x01, 0x00, mylocalBTAddress,
                              AddressFFFFFFFF)
    pluspacket1 = SMANET2PlusPacket(0x09, 0xa0, packet_send_counter,
                                    InverterCodeArray, 0, 0, 0)
    pluspacket1.pushRawByteArray(
        bytearray([
            0x80, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00
        ]))
    send.pushRawByteArray(pluspacket1.getBytesForSending())
    send.finish()
    send.sendPacket(btSocket)

    bluetoothbuffer = read_SMA_BT_Packet(btSocket, packet_send_counter, True,
                                         mylocalBTAddress)
    checkPacketReply(bluetoothbuffer, 0x0001)
    if bluetoothbuffer.leveltwo.errorCode() > 0:
        print("Error code returned from inverter")

    packet_send_counter += 1

    inverterSerial = bluetoothbuffer.leveltwo.getDestinationAddress()
    #LogMessageWithByteArray("inverterSerial", inverterSerial)

    send = SMABluetoothPacket(0x3b, 0, 0x00, 0x01, 0x00, mylocalBTAddress,
                              AddressFFFFFFFF)
    pluspacket1 = SMANET2PlusPacket(0x08, 0xa0, packet_send_counter,
                                    InverterCodeArray, 0x00, 0x03, 0x03)
    pluspacket1.pushRawByteArray(
        bytearray([0x80, 0x0E, 0x01, 0xFD, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]))
    send.pushRawByteArray(pluspacket1.getBytesForSending())
    send.finish()
    send.sendPacket(btSocket)

    # No reply for packet 2 is received
    # bluetoothbuffer = readSMABluetoothPacket(ref level2Packet, btSocket, packet_send_counter, true,mylocalBTAddress);
    packet_send_counter += 1