Flutter将int转换为字节(用PLC,RTC扑打)
我尝试将int转换为字节,找不到一个示例,
我需要在tcp ip中转换int int int int int int int int int int int int int int in tcp ip
final server = await ServerSocket.bind(ip,port);
try{
server.listen((Socket socket) {
int a = 10; // line feed
int b = 36; // $
int c = 122; // z
const sec = Duration(seconds:1);
Timer.periodic(sec,(Timer t) {
socket.wite('data : $a,$b,$c');
});
} on SocketExeption catch(ex) {
print(ex.message);
}
,并且我恢复了
|d|a|t|a| |:|1|0|,|3|6|,|1|2|2|
我如何
|d|a|t|a| |:|LF|,|$|,|z| or |d|a|t|a| |:|0x0A|,|$|,|z|
使用plc的recive recive我,他喜欢绝对索引中的字节,
这是可能的?
使用
int a = 0;
for(;;){
socket.write(String.fromCharCode(a));
a++;
if(a>=256)a=0;
}
如果在任何情况下都可以在TCP IP上
byte0 =00.01....4F........7D.7E.7F.C2.C2....C2.C2..C2.C2.C3.C3.C3..C3.C3.00.01...
byte1 =00.00....00........00.00.00.80.81....84.85..BE.BF.80.81.82..BE.BF.00.00...
recivie ,我可以使用字符串,但是对于某些协议,这是一大批数据,minimun moltiply x4如果使用3个char和一个分隔符,
我会尝试使用Windows应用程序上的RTC与Windows App上的flutter使用,
我可以创建A
javaServer<-low side code bit/byte->plc
和A and
flutter<-json->javaServer
A and A and A and A and A and And我认为丑陋的
工作谢谢Lepsch
try {
client.listen((Socket socket) {
debugPrint('New TCP client ${socket.address.address}:${socket.port} connected.');
List<int> bytes = List.empty(growable: true);
for (var i = 0; i < 255; i++) {
bytes.add(i);
}
Timer.periodic(const Duration(seconds: 1), (Timer t) {
for (var i = 0; i < 255; i++) {
socket.add([bytes[i]]);
}
});
});
} on SocketException catch (ex) {
debugPrint(ex.message);
Timer.periodic(Duration(seconds: 1), (Timer t) {
startServer();
});
}
i'm try to convert int to byte and cant find an example working fo me
i need convert int in byte or bytes to sent in tcp ip
final server = await ServerSocket.bind(ip,port);
try{
server.listen((Socket socket) {
int a = 10; // line feed
int b = 36; // $
int c = 122; // z
const sec = Duration(seconds:1);
Timer.periodic(sec,(Timer t) {
socket.wite('data : $a,$b,$c');
});
} on SocketExeption catch(ex) {
print(ex.message);
}
and i recive
|d|a|t|a| |:|1|0|,|3|6|,|1|2|2|
how i can recive
|d|a|t|a| |:|LF|,|$|,|z| or |d|a|t|a| |:|0x0A|,|$|,|z|
i work with plc and he like bytes in absolute indexing
it's possible?
if use
int a = 0;
for(;;){
socket.write(String.fromCharCode(a));
a++;
if(a>=256)a=0;
}
recive over tcp ip
byte0 =00.01....4F........7D.7E.7F.C2.C2....C2.C2..C2.C2.C3.C3.C3..C3.C3.00.01...
byte1 =00.00....00........00.00.00.80.81....84.85..BE.BF.80.81.82..BE.BF.00.00...
In any case i can use strings but for some protocols it's a huge of data, minimun moltiply x4 if use 3 char and one separator
i try use RTC with flutter on windows app
for the last project i create a
javaServer<-low side code bit/byte->plc
and
flutter<-json->javaServer
i think is ugly
work thanks LEPSCH
try {
client.listen((Socket socket) {
debugPrint('New TCP client ${socket.address.address}:${socket.port} connected.');
List<int> bytes = List.empty(growable: true);
for (var i = 0; i < 255; i++) {
bytes.add(i);
}
Timer.periodic(const Duration(seconds: 1), (Timer t) {
for (var i = 0; i < 255; i++) {
socket.add([bytes[i]]);
}
});
});
} on SocketException catch (ex) {
debugPrint(ex.message);
Timer.periodic(Duration(seconds: 1), (Timer t) {
startServer();
});
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
而不是使用
socket.write
来编写应该使用add
编写字节列表的字符。从从0到255的所有字节的示例中,您需要做以下类似的操作:
在上面的情况下,您将在客户端上得到以下类似的内容:
Instead of using
socket.write
to write the character you should use theadd
to write a list of bytes.From your example with all bytes from 0 to 255 you need to do something like below:
With this above you're going to get something like below on the client-side: