|
Nicely done.
This space for rent
|
|
|
|
|
I am trying to communicate with a TurnStile but cant understand how that build their commands.
This is example of command:
[^]
The command is 0xA005 as it states as CMD but it shows as 05 A0 ... confuses me. Is that really correct? Shoudn't it be A0 05? Any reason for doing it backwards?
CRC16 calculation of command should be "1F 4A" according to that example but I have tried to calculate for that command I cant get same result.
Anyone can help me with that CRC15 calculation?
Regards // Maw
|
|
|
|
|
MaWeRic wrote: Is that really correct? Shouldn't it be A0 05? Well 05 A0 is what they say, so I'm inclined to believe it. Though sending little endian over the network is a bit unusual, it is not all that weird.
As for the CRC16, it seems to use one of the CRC-CCITT polynomials, 0x1021. (I just tried a bunch..)
You should be able to plug that in already available crc code.
|
|
|
|
|
HeyyThanks!
If I try this calculator :
[^]
I try calculate : 05A0
Looking at "CRC-CCITT (XModem)" the result is correct but backwards. Why is that?
Edit: I guess I should send it as 1F4A as documentation says?
I am totally new to this with UDP and sending bytes. But I gess id I dont ask I dont learn
I goggled Little and big endians and I guess little endians means sending reversed order?
//Henrik
|
|
|
|
|
Yes that's probably little endian again.
|
|
|
|
|
Hello,
I am using 'FileSystemWatcher.enableraiseevents' to get the events when a directory, or file in a directory changes.
Initially I have enabled the component and was working properly.
After some time it stopped detecting events, when I check the 'EnableRaisingEvents' it was set to 'False'. In my code I am not setting it to false anywhere.
Is there any possibilities that 'EnableRaisingEvents' sets to 'False' automatically ?
Or what is the cause for my error ?
Please help me.
|
|
|
|
|
Hello, are there any guidelines to migrating a .Net 2.5 application to seamless windows 10 usage?
Or is 2.5 before .net has started its decline into platform nuances and quirks?
|
|
|
|
|
The application should run without problems on Windows 10.
|
|
|
|
|
1) There is no such thing as .NET 2.5 - see .NET Framework version history[^].
2) I suggest you change your username, as it currently makes you look like a spammer.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
0
down vote
favorite
I'm struggling with navigation in asp.net mvc and URLs.
When you are visiting your profile at facebook, the url is facebook.com/yourusername.
At your profile there is a menu with the following links: Timeline, About, Friends etc.
When you click on one of these links, for example Photos, the URL is changed to facebook.com/yourusername/Photos, and the photos are rendered. The menu described above are still there, and so also the profile picture and the cover picture. Its like a partial view has rendered viewing the photos.
I want to accomplish this effect in my project, but I don't know how to do it. I have tried to do it with Partial view but the problem is that the URL is not changed when the partial view is rendered.
Anyone can help me with this? How should I structure it?
|
|
|
|
|
Please use the correct forum for your question. This is not a C# issue.
|
|
|
|
|
Hi,
I have the following code:
<div class="col-lg-12 pull-left">
<div class="user_menu">
<ul>
<li>@Ajax.ActionLink("Wall", "Wall", "Home", new AjaxOptions { UpdateTargetId = "main" })</li>
</ul>
</div>
</div>
<div id="main" class="col-lg-7 pull-left" style="margin-top: 15px;">
</div>
The partial view Is rendered as expected inside my main div. But I want the URL to change when you render the partial. How can I do this?
So when I click on the link, I want to render the partial inside my div AND change the div to http://localhost123/Home/Wall
|
|
|
|
|
|
I've tried code similar to what is below, I keep getting an error that says a parameter is missing and when I trace the error it appears the parameter name is "message" and it is blank.
How can I download an image in powershell, keep it in memory (not save it to a file) and then display it in a picturebox in c#?
I see this error mentioned 100's of times on the net and no one has an answer?
[code]
byte[] pictureByteArray = new byte[0];
object pictureObject = new object();
Collection<PSObject> results = powershellExchange.Invoke();
foreach (PSObject result in results)
{
pictureObject = (result.Properties["PictureData"].Value);
pictureByteArray = Encoding.ASCII.GetBytes(result.Properties["PictureData"].ToString());
}
byte[] originalCoverData;
BinaryFormatter bf = new BinaryFormatter();
using (var ms = new MemoryStream())
{
bf.Serialize(ms, pictureObject);
originalCoverData = ms.ToArray();
}
Image x = null;
x = byteArrayToImage(originalCoverData);
System.IO.MemoryStream stream = new System.IO.MemoryStream(originalCoverData);
pbxDisplayPicture.Image = x;
System.Drawing.Image img2 = System.Drawing.Image.FromStream(stream);
pbxDisplayPicture.Image = img2;
[/code]
[code]
public Image byteArrayToImage(byte[] byteArrayIn)
{
using (MemoryStream mStream = new MemoryStream(byteArrayIn))
{
return Image.FromStream(mStream);
}
}
[/code]
|
|
|
|
|
Where does the error occur?
|
|
|
|
|
Sorry for the delay, it always tells me
"Parameter is not valid" for mStream
public Image byteArrayToImage(byte[] byteArrayIn)
{
using (MemoryStream mStream = new MemoryStream(byteArrayIn))
{
return Image.FromStream(mStream);
}
}
The particular byte array in question is 8716 items, so it seems like the byte array is valid
|
|
|
|
|
turbosupramk3 wrote: it seems like the byte array is valid Are you sure it contains a valid image? The error message suggests that it does not.
|
|
|
|
|
 No I am not, do you have a suggestion on another way I can check?
The code under the Exception snapshot, always has the same error message with the Parameter is not valid at
Quote: at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData)
at System.Drawing.Image.FromStream(Stream stream)
at Updator.PictureUpdater.btnViewPicture_Click(Object sender, EventArgs e) in c:\Users\xxxx\Documents\Visual Studio 2012\Projects\Updator\Updator\Form1.cs:line 245
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at Updator.Program.Main() in c:\Users\xxx\Documents\Visual Studio 2012\Projects\Exchange Picture Updator\Updator\Program.cs:line 19
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
modified 24-May-16 17:25pm.
|
|
|
|
|
I figured it out, I had to build my own byte array and not use memory stream. Memory stream was corrupting the file and making it an additional 28 bytes. I'm not sure why this wasn't on the internet, as it seems 100's of people encounter this?
Thanks for pointing me in the right direction.
byte[] imgBytes = null;
List<byte> imgBytesList = new List<byte>();
object imgObj = null;
Image img = null;
foreach (PSObject obj in exResults)
{
imgObj = obj.Properties["PictureData"].Value;
}
foreach (byte byt in (dynamic)imgObj)
{
imgBytesList.Add(byt);
}
imgBytes = imgBytesList.ToArray();
using (var ms = new MemoryStream(imgBytes))
{
img = Image.FromStream(ms);
}
pbxDisplayPicture.Image = img;
|
|
|
|
|
I have an application that uses a COM object to make a connection to an application. I need to make sure that when my application ends that I call the EndSession and CloseConnection methods of this COM object. I was reading this article: Implementing IDisposable and the Dispose Pattern Properly[^] as I think this is what I would need to do to make sure my closing code always gets called, but it doesn't seem to happen when I stop debugging. The application that I am connecting to still thinks my program is connected. It seems like when I stop debugging (or if I have a program crash, that the Dispose methods don't get called. I also tried to add a Finalizer but that causes a System.Runtime.InteropServices.InvalidComObjectException stating that the COM object that has been separated from it's underlying RCW cannot be used.
private bool disposed;
protected virtual void Dispose(bool disposing)
{
if (!disposed)
{
if (_Session != null)
{
_Session.EndSession();
_Session.CloseConnection();
_Session = null;
}
disposed = true;
}
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
~SessionConnection()
{
Dispose(false);
}
I'm not sure what is the best way to ensure that the EndSession and CloseConnection methods of my COM object get called even if my program crashes or I stop debugging.
|
|
|
|
|
I doesn't "seem" like you are sure if Dispose() is getting called so you should add a "log entry" in Dispose() to be sure.
Your "session" instance looks private.
You could try (pardon the pun), a higher level "try ... finally", where the finally always runs and checks your object for null, disposes it, etc.
Then there are application level exception handlers and "exits" ... you need to log to understand which paths your particular app can end on.
|
|
|
|
|
When you launch the code from inside Visual Studio, it's launched, the debugger is attached and you debug on your merry way. If you hit Stop inside Visual Studio, your code is stopped, wherever it is, and removed from memory. Your Dispose code never gets executed.
The only way to make sure it does is if you exit your application as a user would, gracefully.
|
|
|
|
|
That's what I was going to say!
The only thing I'd add is that the same thing will happen if you use Task Manager to kill the process. So if this is causing a problem with "Stop debugging" it'll also cause the same problem if the user terminates the app.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I never knew that about the debugger, thanks! But then does this mean that GC doesn't do any cleanup? Or is Visual Studio maintaining the information so it knows to release any allocated memory? Is this something to do with the VS Hosting Process? If I open a file within a using statement, it seems like stopping the debugger is still releasing the file handle (at least I think so, I'm still very new).
Are there any recommendations / best practices when dealing with situations like this?
|
|
|
|
|
There is no cleanup of the orphaned COM stuff. It's just left hanging. When the code is stopped abruptly, the GC doesn't even run. Your process is stopped cold and the memory the app and its data was occupying freed and returned to Windows.
The GC cannot clean up non-managed resources anyway. It can only cleanup managed stuff. The closest it can get is to free up the managed COM-wrapper that's is hanging onto the unmanaged COM references, but this doesn't free up those unmanaged resources. They are just orphaned.
The debugger doesn't release anything at all. It's just attached to the process, not executing or controlling it in any meaningful way.
|
|
|
|