Only the manufacturer of 41 bytes will deliver the future in a single time.
If it does not come in one go as you have stated, how can I get it in the order of the results?
So how do I get to 8 + 8 + 8 + 8 in order of incoming results?
Serial devices present their data in "chunks", and each chunk may be anything from a single byte to a complete message. This is a feature of serial IO that the programmer needs to understand and deal with. Your input routine needs to capture however much data is presented each time, and build the message buffer by appending the latest 'chunk' to whatever has already been read in. When you are certain that you have all the available data you can go and process it. If the manufacturer tells you that you will receive 41 bytes, then you must keep reading until your message has received that number of bytes.
Set an index to the start of your receive buffer
Read some data using the index to position it at the correct point in the buffer
Add the count of bytes read to the offset index
While index < 41
// when the index reaches 41 you have all the data (bytes 0 to 40)
serial communication can be very hard, and it can be quite easy; it all depends on circumstances: how high the transmission rate is, how big the gap is in between messages, etc.
Here are three pointers, assuming the peripheral uses printable text:
1. Always use a terminal emulator to get acquainted with your peripheral's behavior. It will help you in checking the hardware aspects and overall settings of your port, and it will help you in understanding the message flow.
2. the DataReceived event fires whenever it wants, which could be after receiving 1 byte, or 39 bytes, or whatever. It does not care about what you expect as a message, it only knows about individual bytes and several levels of buffering inside Windows. As a result it isn't very useful except in simple cases:
If your messages are far apart, which gives you some time to waste, the easiest approach is to get started by the DataReceived event, then wait (with Thread.Sleep) sufficiently long so the entire message should be received by now, and then use ReadExisting. The required delay equals maximum string length * character time, which obviously depends on the baud rate used (say 1 msec at 9600 baud). Warning: Windows timing isn't always very accurate, so add a spare 20 msec or so.
I am not a c# developer. I am creating an ETL in Visual Studio 2017 and trying to add a scripted transformation container to strip the /'s out of a name field. VS creates the base code and tells you where to add the code.
This is the beginning:
egion Help: Introduction to the Script Component
/* The Script Component allows you to perform virtually any operation that can be accomplished in
* a .Net application within the context of an Integration Services data flow.
* Expand the other regions which have "Help" prefixes for examples of specific ways to use
* Integration Services features within this script component. */#endregion
///<summary>/// This is the class to which to add your code. Do not change the name, attributes, or parent
/// of this class.
publicclass ScriptMain : UserComponent
#region Help: Using Integration Services variables and parameters
/* To use a variable in this script, first ensure that the variable has been added to
* either the list contained in the ReadOnlyVariables property or the list contained in
* the ReadWriteVariables property of this script component, according to whether or not your
* code needs to write into the variable. To do so, save this script, close this instance of
* Visual Studio, and update the ReadOnlyVariables and ReadWriteVariables properties in the
* Script Transformation Editor window.
* To use a parameter in this script, follow the same steps. Parameters are always read-only.
* Example of reading from a variable or parameter:
* DateTime startTime = Variables.MyStartTime;
* Example of writing to a variable:
* Variables.myStringVariable = "new value";
#region Help: Using Integration Services Connnection Managers
/* Some types of connection managers can be used in this script component. See the help topic
* "Working with Connection Managers Programatically" for details.
* To use a connection manager in this script, first ensure that the connection manager has
* been added to either the list of connection managers on the Connection Managers page of the
* script component editor. To add the connection manager, save this script, close this instance of
* Visual Studio, and add the Connection Manager to the list.
* If the component needs to hold a connection open while processing rows, override the
* AcquireConnections and ReleaseConnections methods.
* Example of using an ADO.Net connection manager to acquire a SqlConnection:
* object rawConnection = Connections.SalesDB.AcquireConnection(transaction);
* SqlConnection salesDBConn = (SqlConnection)rawConnection;
* Example of using a File connection manager to acquire a file path:
* object rawConnection = Connections.Prices_zip.AcquireConnection(transaction);
* string filePath = (string)rawConnection;
* Example of releasing a connection manager:
#region Help: Firing Integration Services Events
/* This script component can fire events.
* Example of firing an error event:
* ComponentMetaData.FireError(10, "Process Values", "Bad value", "", 0, out cancel);
* Example of firing an information event:
* ComponentMetaData.FireInformation(10, "Process Values", "Processing has started", "", 0, fireAgain);
* Example of firing a warning event:
* ComponentMetaData.FireWarning(10, "Process Values", "No rows were received", "", 0);
///<summary>/// This method is called once, before rows begin to be processed in the data flow.
////// You can remove this method if you don't need to do anything here.
* Add your code here
Where it says add your code here I have tried multiple suggestions I have found online, but it doesn't like the syntax. I don't know if I have to declare the field, or what I'm missing. The most promising looked like the Regex function, but it will not recognize it regardless of how I type it. Any help here would be extremely appreciated!
Once you get the current value of the variable, you can simply do this to remove all the "/" characters:
myVariable = myVariable.Replace("/", "");
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
Are you looking to write your own WeakEventHandler implementation or could you just use one of the pre-built ones, listed in the inheritance tree, here[^]?
The code probably doesn't compile because the example is not meant as a copy'n'paste example. You have to replace certain works in the source with either your own implementations or with interface names of the event type you're looks for. You'd probably even have to extend WeakEventManager with your own implementations of certain methods, depending on what you're doing.
There are no "simple" examples of this thing. About the only thing I could suggest is looking at the .NET Reference Source for a similar implementation of what you're trying to do and using that as a framework to write your own code. For example, the source for PropertyChangedEventManager can be found here[^].
OK, I see what you're getting at. Unfortunately, I've never seen a "simple" implementation of this. What I've done in the past is something very similar to the implementation found in the Prism library. The latest source for the EventAggregator in there can be found here[^].