只获得大型可变组的变异 [英] Get only variation from large valriable bunch

查看:50
本文介绍了只获得大型可变组的变异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有



我需要开发一个包含100多个变量的程序。正在改变不同的功能。



我需要通过串口发送此变量仅在更改时不为每个定义新的更多变量。





我尝试为每个变量定义新变量并存储该值。然后,如果新的值存储在原始变量中,则执行该函数。下面我就像我一样展示这个例子。







这个全部函数由一个计时器执行vb.net



谢谢



问候

Nayana



我的尝试:



 公开  Form1 

Dim newDistance 作为 整数
Dim 距离作为 整数

私人 Sub functionX()

结束 Sub

私有 Sub Timer1_Tick( By Val sender As System。 Object ByVal e As System.EventArgs)句柄 Timer1.Tick
如果 newDistance<>距离然后
functionX()
newDistance =距离
结束 < span class =code-keyword>如果
结束 Sub

结束

解决方案

你正在做的最糟糕的事情是处理计时器滴答。你认为事情将如何与那些滴答同步。我甚至不讨论这个我不理解的逻辑;我只是面对一些具有计时器思维的开发人员,我宁愿称之为反思。你不必解释你背后的理由,但如果可以,你会很好奇。你真的不需要时间或同步任何东西。您应该无条件地发送数据。更有趣的是,接收方应该这样做。但由于流通常互相锁定,因此在单独的线程中进行双方的所有通信是很重要的,或者在某些情况下,在每一侧都有一些专用于串行通信的线程。



你只需要使用类 System.IO.Ports.SerialPort

SerialPort Class(System.IO.Ports) [ ^ ]。



现在,它的第二个方面:你不应该只发送你所谓的变量;这种方法完全没有结构化,会把你带到任何地方。您应该在发送之前创建一些数据结构,您可以序列化,并在收到之前反序列化。这是一个名为序列化的独立主题:

序列化 - 维基百科,免费的百科全书 [ ^ ],

https://msdn.microsoft.com/en-us/library/ms233843.aspx [ ^ ],

System.Runtime.Serialization命名空间 [ ^ ],

二进制序列化 [ ^ ],

使用数据合同 [ ^ ],

DataContractSerializer类(System.Runtime.Serialization) [ ^ ],[ ^ ],

DataCont ractJsonSerializer类(System.Runtime.Serialization.Json) [ ^ ]。



-SA

Dear All

I need Develop one Program It Contain More Than 100 Of variable. The are changing with different function.

I need to send this variable through the serial Port Only if it is changed Without Defining new more variable for each.


I tried defined New variable for each and stored the value. Then new value stored in original variable if it is different i execute the function. Below I just show the example as I did.



This all function Execute by a timer in vb.net

Thanks

Regards
Nayana

What I have tried:

Public Class Form1

    Dim newDistance As Integer
    Dim Distance As Integer

    Private Sub functionX()

    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If newDistance <> Distance Then
            functionX()
            newDistance = Distance
        End If
    End Sub

End Class

解决方案

Worst thing you are doing is handling the timer ticks. How do you think things are going to be synchronized with those ticks. I don't even what to discuss this logic which I don't understand; I just face a number of developers with such "timer thinking" which I would rather call "anti-thinking". You don't have to explain your rationale behind that, but if you can, it would be curious to hear. You don't really need to "time" or synchronize anything. You should just unconditionally send the data. More interestingly, the receiving side should do the same. But as the streams are generally lock each other, it would be important to do all the communications on both sides in separate threads, or, in some cases, some couple of threads dedicated to serial communications on each side.

You just need to use the class System.IO.Ports.SerialPort:
SerialPort Class (System.IO.Ports)[^].

Now, the second aspect of it: you should not just send what you call "variables"; such approach would be totally non-structured, would take you anywhere. You should create some data structure which you can serialize before you send it and deserialize before you receive. This is a separate topic called serialization:
Serialization — Wikipedia, the free encyclopedia[^],
https://msdn.microsoft.com/en-us/library/ms233843.aspx[^],
System.Runtime.Serialization Namespace[^],
Binary Serialization[^],
Using Data Contracts[^],
DataContractSerializer Class (System.Runtime.Serialization)[^],[^],
DataContractJsonSerializer Class (System.Runtime.Serialization.Json)[^].

—SA


这篇关于只获得大型可变组的变异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆