Scott A Burch

Ranch Hand
+ Follow
since Jan 04, 2011
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Scott A Burch

A stream of six bytes coming in as hex values like so:

30
32
34
39
38
38

Should translate to "024988" in ASCII if I have the UTF-8 setting correct. How can I take those ASCII numbers and format them as "02.49.88"?

Thanks.
8 years ago
Let me correct another mistake: the bytes coming in will be hex, and need to display as ASCII. Sorry, but I had it the wrong way around.
8 years ago
Sorry about that. I re-read the specifications for the incoming stream and 6 bytes will be coming in on the datainputstream  - sorry, long day. These bytes will be ASCII codes and will range only from 0-9. The format I'd like to use for display on println will be "xx.xx.xx", e.g., 02.13.12. What custom format can I use to display them as such? Also, is UTF-8 the proper char set to display ASCII?

Thanks again.

8 years ago
The method below should receive in some bytes that I need to format for print output in this way:

xx.xx.xxxx

How do I format the variable "message"?



thank you!
8 years ago
I have a working program that has a Timer that gets its start date and time from a Date JSpinner, then fires a TimerTask to complete a task. It works perfectly well. As an experiment, I set up a second Date JSpinner with a date much later than the first to see if it would fire the same TimerTask again at the later date and time. It did not. Is a TimerTask ever reusable, or am I doing something wrong? Should the second Date JSpinner be associated with its own separate TimerTask? I could post the code, but it may be quicker to ask the question first in case I'm barking up the wrong tree.

Thank you.
9 years ago
I am using a DateSpinner to get a date and time to begin a task. I am trying to use java.time, but the error I am getting when converting to string through the formatter tells me that the getValue method is outputting a util.date, incompatible with java.time. Is there a way to get a string value from DateSpinner that is compatible with java.time? Or should I not use java.time and go back to using the older util.date?

Thanks as always!


[code=java]

try {
//Date and time to start event

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM-dd-yy hh:mm a");
String aTime = formatter.format(aSpinner.getValue()); // this is the problem!
jTextArea1.append("date is " + aTime);
LocalDateTime aDateTime = LocalDateTime.parse(aTime, formatter);
Instant instant = aDateTime.atZone(ZoneId.systemDefault()).toInstant();
Date aDate = Date.from(instant);

timer.schedule(new ATask(), aDate);

} catch (DateTimeException e) {
System.exit(0);
}


[/code]
9 years ago
Thread.sleep is what I was looking for ... it's purpose is for pacing. Just read the Oracle doc on the subject. Thanks to all for the suggestions.
I am writing a program that is delivering bytes over a socket to a machine that responds to commands. The machine needs at least 100 milliseconds between commands to execute properly. I have one sequence that is sending too quickly. How do I build in a delay of 200 milliseconds between commands?

thanks!
Made the change and it works perfectly. Thanks again!
9 years ago
Thanks for the reply. Just for my education, what does that change do in terms of performance?
9 years ago
It compiles and runs, but system exit is being invoked in the dataoutputstream section "System.err.println("Caught IOException: xxxx "); " around line 80. It could be writing hex to the datastream all wrong, or it's the wrong stream ( bytearray stream? ), or it's not getting the Socket ipAddress and port parameters and timing out, or all the above. Any suggestions? Thanks !


9 years ago
This is a console application, the purpose of which is to write a byte to a network socket using a TimerTask. Compiling gives me an error on line 23 - which I knew would happen - that the variable deviceSocket cannot be found. I created it in the main section of the program because that's where the user answers questions about start and stop times, and IP address and port info. My problem is that I'm stuck for alternatives - how can I restructure this so that the variable can be found? It has to be in the StartTask TimerTask because the byte needs to written only when StartTask executes. Is it possible to ask for console input outside the main section of the program? When I tried that, I wound up with lots more errors and got really lost. Thanks!




9 years ago
that's what I was looking for. Thanks again!
12 years ago
Let me try to explain this better. Got rushed on posting yesterday and messed it up - sorry for the confusion. I am posting abstracted code that goes to the heart of the question; there is too much other code to post have it compile. The code was originally written as a console application, that is, no GUI. I could put the integer values directly into the main() method, compile it, and it would run. What I am trying to do is give it a GUI, specifically, the integer values in the main() method are supplied by three JSpinners. I am looking for suggestions as to how I can express the main() method without running into the nonstatic variable problem. I know the integer arguments cannot live in the main() method, I just don't know of an alternative. Suggestions? (Besides give up?) Thanks!


12 years ago