This commit is contained in:
parent
06b8560412
commit
5b2d4bce64
|
@ -73,12 +73,22 @@ ComProxy::ComProxy(COM com) :port(com)
|
||||||
Name = port.Name;
|
Name = port.Name;
|
||||||
String name(Name);
|
String name(Name);
|
||||||
name.Show(true);
|
name.Show(true);
|
||||||
|
|
||||||
|
baudRate = 115200;
|
||||||
|
|
||||||
|
parity = 0x0000; // USART_Parity_No;
|
||||||
|
dataBits = 0x0000; // USART_WordLength_8b;
|
||||||
|
stopBits = 0x0000; // USART_StopBits_1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ComProxy::OnOpen()
|
bool ComProxy::OnOpen()
|
||||||
{
|
{
|
||||||
return port.Open();
|
if (port.Open())
|
||||||
// return true;
|
{
|
||||||
|
port.SetBaudRate(baudRate);
|
||||||
|
port.Set(parity, dataBits, stopBits);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ComProxy::OnClose()
|
bool ComProxy::OnClose()
|
||||||
|
@ -90,13 +100,13 @@ bool ComProxy::OnClose()
|
||||||
bool ComProxy::SetConfig(Dictionary<cstring, int>& config, String& str)
|
bool ComProxy::SetConfig(Dictionary<cstring, int>& config, String& str)
|
||||||
{
|
{
|
||||||
int value;
|
int value;
|
||||||
if (config.TryGetValue("baudRate", value))
|
if (config.TryGetValue("baudrate", value))
|
||||||
{
|
{
|
||||||
port.SetBaudRate(value);
|
port.SetBaudRate(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
cstring ByteParam[] = { "parity","dataBits","stopBits" };
|
cstring ByteParam[] = { "parity","dataBits","stopBits" };
|
||||||
byte* ParamP[] = {&parity, &dataBits, &stopBits};
|
ushort* ParamP[] = {&parity, &dataBits, &stopBits};
|
||||||
bool haveChang = false;
|
bool haveChang = false;
|
||||||
for (int i = 0; i < ArrayLength(ByteParam); i++)
|
for (int i = 0; i < ArrayLength(ByteParam); i++)
|
||||||
{
|
{
|
||||||
|
@ -114,7 +124,7 @@ bool ComProxy::SetConfig(Dictionary<cstring, int>& config, String& str)
|
||||||
|
|
||||||
bool ComProxy::GetConfig(Dictionary<cstring, int>& config)
|
bool ComProxy::GetConfig(Dictionary<cstring, int>& config)
|
||||||
{
|
{
|
||||||
config.Add("baudRate",baudRate);
|
config.Add("baudrate",baudRate);
|
||||||
|
|
||||||
config.Add("parity", parity);
|
config.Add("parity", parity);
|
||||||
config.Add("dataBits", dataBits);
|
config.Add("dataBits", dataBits);
|
||||||
|
|
|
@ -43,9 +43,9 @@ public:
|
||||||
|
|
||||||
SerialPort port;
|
SerialPort port;
|
||||||
|
|
||||||
byte parity;
|
ushort parity;
|
||||||
byte dataBits;
|
ushort dataBits;
|
||||||
byte stopBits;
|
ushort stopBits;
|
||||||
int baudRate;
|
int baudRate;
|
||||||
|
|
||||||
virtual bool OnOpen() override;
|
virtual bool OnOpen() override;
|
||||||
|
|
|
@ -13,9 +13,9 @@ class SerialPort : public ITransport, public Power
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
byte _index;
|
byte _index;
|
||||||
byte _parity;
|
ushort _parity;
|
||||||
byte _dataBits;
|
ushort _dataBits;
|
||||||
byte _stopBits;
|
ushort _stopBits;
|
||||||
int _baudRate;
|
int _baudRate;
|
||||||
|
|
||||||
void* _port;
|
void* _port;
|
||||||
|
|
|
@ -168,24 +168,36 @@ bool ProxyFactory::GetConfig(const BinaryPair& args, Stream& result)
|
||||||
// port->GetConfig(str); // 调用端口的函数处理内容
|
// port->GetConfig(str); // 调用端口的函数处理内容
|
||||||
// ms.Write(str);
|
// ms.Write(str);
|
||||||
|
|
||||||
Dictionary<cstring, int> cfg(String::Compare);
|
Dictionary<cstring, int> cfg;
|
||||||
port->GetConfig(cfg); // 调用端口的函数处理内容
|
port->GetConfig(cfg); // 调用端口的函数处理内容
|
||||||
|
|
||||||
// 数据先写进缓冲区ms2
|
// 数据先写进缓冲区ms2
|
||||||
MemoryStream ms2;
|
MemoryStream ms2;
|
||||||
auto name = cfg.Keys();
|
auto name = cfg.Keys();
|
||||||
auto value = cfg.Keys();
|
auto value = cfg.Values();
|
||||||
|
|
||||||
|
debug_printf("cfg count : %d value count : %d\t\t", name.Count(), value.Count());
|
||||||
|
String str;
|
||||||
|
|
||||||
for (int i = 0; i < cfg.Count(); i++)
|
for (int i = 0; i < cfg.Count(); i++)
|
||||||
{
|
{
|
||||||
ms2.Write(String(name[i]));
|
str = str + name[i] + '=' + value[i];
|
||||||
ms2.Write('=');
|
if (i < cfg.Count() - 1)str = str + ',';
|
||||||
ms2.Write(String(value[i]));
|
|
||||||
if (i < cfg.Count() - 1) ms2.Write('&');
|
|
||||||
}
|
}
|
||||||
// 然后组成名词对写进回复数据内去
|
str.Show(true);
|
||||||
BinaryPair bp(ms);
|
//ms.Write(str);
|
||||||
bp.Set("Config", Buffer(ms2.GetBuffer(), ms2.Position()));
|
result.Write(str);
|
||||||
|
|
||||||
|
// for (int i = 0; i < cfg.Count(); i++)
|
||||||
|
// {
|
||||||
|
// ms2.Write(String(name[i]));
|
||||||
|
// ms2.Write('=');
|
||||||
|
// ms2.Write(String(value[i]));
|
||||||
|
// if (i < cfg.Count() - 1) ms2.Write('&');
|
||||||
|
// }
|
||||||
|
// // 然后组成名词对写进回复数据内去
|
||||||
|
// BinaryPair bp(ms);
|
||||||
|
// bp.Set("Config", Buffer(ms2.GetBuffer(), ms2.Position()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue