/// <summary> /// Request to delete the file. /// </summary> /// <param name="fileType">FileType enum value to distinguish whether the file is log or offline data</param> /// <param name="fileName">Filename (56 byte length limit)</param> /// <exception cref="FileNameIsTooLongException">Occurs when file name is longer than 56 bytes</exception> /// <exception cref="IsNotActiveException">Occurs when communication with the pen is not established</exception> public void DeleteFileRequest(FileType fileType, string fileName) { if (!IsActive) { throw new IsNotActiveException(); } var filePathBytes = Encoding.UTF8.GetBytes(fileType == FileType.Data ? DataFilePath + fileName : LogFilePath + fileName); if (filePathBytes.Length > 64) { throw new FileNameIsTooLongException(); } var builder = new UsbPacket.Builder(); builder.Cmd(Cmd.DELETEFILE) .PacketNumber(++packetNumber) .Type(PacketType.Request) .Put(filePathBytes, 64); byte[] result = builder.Build().ToArray(); _serialPort?.Write(result, 0, result.Length); }
private void SetConfigRequest(ConfigType type, object value) { var builder = new UsbPacket.Builder(); builder.Cmd(Cmd.SETCONFIG) .PacketNumber(++packetNumber) .Type(PacketType.Request) .Put((byte)0x01) .Put((byte)type); switch (type) { case ConfigType.DateTime: builder.PutLong((long)value); break; case ConfigType.AutoPowerOffTime: builder.PutShort((short)value); break; case ConfigType.AutoPowerOn: case ConfigType.PenCapOff: case ConfigType.Beep: case ConfigType.SaveOfflineData: case ConfigType.DownSampling: builder.Put((byte)((bool)value ? 0x01 : 0x00)); break; } byte[] result = builder.Build().ToArray(); _serialPort?.Write(result, 0, result.Length); }
private void GetDeviceInfoRequest() { var builder = new UsbPacket.Builder(); builder.Cmd(Cmd.GETDEVINFO) .PacketNumber(++packetNumber) .Type(PacketType.Request); byte[] result = builder.Build().ToArray(); _serialPort?.Write(result, 0, result.Length); }
private void GetFilePacketRequest(int index) { var builder = new UsbPacket.Builder(); builder.Cmd(Cmd.GETFILE_D) .PacketNumber(++packetNumber) .Type(PacketType.Request) .PutInt(index) .PutInt(fileSerializer.GetPacketSize(index)); byte[] result = builder.Build().ToArray(); _serialPort?.Write(result, 0, result.Length); }
private void StartRequest() { var builder = new UsbPacket.Builder(); builder.Cmd(Cmd.START) .PacketNumber(packetNumber) .Type(PacketType.Request) .PutInt(2) .Put((byte)0x00); byte[] result = builder.Build().ToArray(); _serialPort?.Write(result, 0, result.Length); }
private void UpdatePacketUploadRequest(int offset, byte[] data) { var builder = new UsbPacket.Builder(); builder.Cmd(Cmd.UPDATE_DO) .PacketNumber(++packetNumber) .Type(PacketType.Request) .PutInt(offset) .PutInt(data.Length) .Put(data); byte[] result = builder.Build().ToArray(); _serialPort?.Write(result, 0, result.Length); }
/// <summary> /// Request a list of log data files currently stored in the pen. /// </summary> /// <exception cref="IsNotActiveException">Occurs when communication with the pen is not established</exception> public void GetLogFileListRequest() { if (!IsActive) { throw new IsNotActiveException(); } var builder = new UsbPacket.Builder(); builder.Cmd(Cmd.GETLOGFILELIST) .PacketNumber(++packetNumber) .Type(PacketType.Request); byte[] result = builder.Build().ToArray(); _serialPort?.Write(result, 0, result.Length); }
/// <summary> /// Request the storage state of the current pen. /// </summary> /// <exception cref="IsNotActiveException">Occurs when communication with the pen is not established</exception> public void GetStorageStatusRequest() { if (!IsActive) { throw new IsNotActiveException(); } var builder = new UsbPacket.Builder(); builder.Cmd(Cmd.GETDISKINFO) .PacketNumber(++packetNumber) .Type(PacketType.Request); byte[] result = builder.Build().ToArray(); _serialPort?.Write(result, 0, result.Length); }
/// <summary> /// Request to initialize the data of the current pen. /// </summary> /// <exception cref="IsNotActiveException">Occurs when communication with the pen is not established</exception> public void FormatRequest() { if (!IsActive) { throw new IsNotActiveException(); } var builder = new UsbPacket.Builder(); builder.Cmd(Cmd.FORMAT) .PacketNumber(++packetNumber) .Type(PacketType.Request) .Put((byte)0); byte[] result = builder.Build().ToArray(); _serialPort?.Write(result, 0, result.Length); }
private void GetConfigRequest(params ConfigType[] types) { var builder = new UsbPacket.Builder(); builder.Cmd(Cmd.GETCONFIG) .PacketNumber(++packetNumber) .Type(PacketType.Request) .Put((byte)types.Length); foreach (var type in types) { builder.Put((byte)type); } byte[] result = builder.Build().ToArray(); _serialPort?.Write(result, 0, result.Length); }
/// <summary> /// Request to update the pen's firmware. /// </summary> /// <param name="firmwareVersion">Version of new firmware (24 byte length limit)</param> /// <param name="filePath">File path of new firmware</param> /// <exception cref="FirmwareVersionIsTooLongException">Occurs when firmware version is longer than 24 bytes</exception> /// <exception cref="FileCannotLoadException">Occurs when the firmware file at the specified location cannot be opened</exception> /// <exception cref="IsNotActiveException">Occurs when communication with the pen is not established</exception> public void UpdateRequest(string firmwareVersion, string filePath) { if (!IsActive) { throw new IsNotActiveException(); } if (isUpdating) { return; } var deviceBytes = Encoding.UTF8.GetBytes(DeviceName); var firmwareVersionBytes = Encoding.UTF8.GetBytes(firmwareVersion); if (firmwareVersionBytes.Length > 24) { throw new FirmwareVersionIsTooLongException(); } fileSplitter = new FileSplitter(); if (!fileSplitter.Load(filePath)) { throw new FileCannotLoadException(); } isUpdating = true; var builder = new UsbPacket.Builder(); builder.Cmd(Cmd.UPDATE_START) .PacketNumber(++packetNumber) .Type(PacketType.Request) .Put(deviceBytes, 24) .Put(firmwareVersionBytes, 24) .PutInt(fileSplitter.FileSize); byte[] result = builder.Build().ToArray(); _serialPort?.Write(result, 0, result.Length); }
public void Put(byte[] buff, int size) { //byte[] test = new byte[size]; //Array.Copy( buff, 0, test, 0, size ); //System.Console.WriteLine( "Read Buffer : {0}", BitConverter.ToString( test ) ); //System.Console.WriteLine(); for (int dataIdx = 0; dataIdx < buff.Length; dataIdx++) { byte recvByte = buff[dataIdx]; switch (step) { case 0: if (recvByte == Const.CMD_PRIFIX_1) { step = 1; } else { step = 0; } break; case 1: if (recvByte == Const.CMD_PRIFIX_2) { step = 2; } else { step = 0; } break; case 2: if (recvByte == Const.CMD_PRIFIX_3) { step = 3; commandIdx = 0; //command[commandIdx++] = recvByte; reqDataLen = 0; m_rawDataCnt = 0; builder = new UsbPacket.Builder(); } else { step = 0; } break; case 3: if (recvByte != Const.CMD_DELIMITER_RESPONSE && recvByte != Const.CMD_DELIMITER_EVENT) { command[commandIdx++] = recvByte; } else { string cmdstring = System.Text.Encoding.Default.GetString(command, 0, commandIdx).Trim('\0').Trim(); Cmd cmd = (Cmd)Enum.Parse(typeof(Cmd), cmdstring); builder.Cmd(cmd); if (recvByte == Const.CMD_DELIMITER_RESPONSE) { //Req builder.Type(PacketType.Response); step = 4; } else if (recvByte == Const.CMD_DELIMITER_EVENT) { //Event builder.Type(PacketType.Event); step = 5; } } break; case 4: builder.PacketNumber(recvByte); step = 6; break; case 5: builder.PacketNumber(recvByte); step = 7; break; case 6: builder.ErrorNumber(recvByte); step = 7; break; case 7: length[0] = recvByte; step = 8; break; case 8: length[1] = recvByte; reqDataLen = BitConverter.ToUInt16(length, 0); step = 9; break; case 9: if (recvByte == Const.CMD_DELIMITER_DATA) { step = 10; } else { step = 0; } break; case 10: builder.Put(recvByte); if ((m_rawDataCnt++ == reqDataLen - 1) || (reqDataLen == 0)) { step = 0; //초기화 PacketCreated(this, new UsbPacketEventArgs(builder.Build())); } break; default: break; } } }